Convenient architectural patterns

Hello, Habr!


In the light of current events, due to coronavirus, a number of Internet services began to receive an increased load. For example, one of the retail chains in the UK simply stopped the site with online orders , as there was not enough capacity. And it is far from always possible to speed up a server by simply adding more powerful equipment, however, customer requests must be processed (or they will go to competitors).


In this article, I will briefly talk about popular practices that will allow you to make a fast and fault-tolerant service. However, from the possible development schemes, I selected only those that are now easy to use . For each item, you either have ready-made libraries, or you can solve the problem using the cloud platform.


Horizontal scaling


The simplest and most well-known item. By convention, the most common are two load balancing schemes - horizontal and vertical scaling. In the first case, you allow the services to work in parallel, thereby distributing the load between them. In the second, you order more powerful servers or optimize the code.


For an example I will take an abstract cloud file storage, that is, some analogue of OwnCloud, OneDrive and so on.


The standard picture of such a scheme is below, however, it only demonstrates the complexity of the system. After all, we need to somehow synchronize the services. What happens if a user saves a file from a tablet and then wants to watch it from a phone?



: , — , .


CQRS


Command Query Responsibility Segregation , , . , ( ) . : . , A, .


— ( ) . - :


  1. .
  2. .
  3. .

, 2 ( , , ). , . CQRS, :


  1. .
  2. .
  3. « ».
  4. «1».


, . , request-response . , . , (, ), , .


, ( 100%) , , , .


, ( RX ). , , . .


, , . , , .


Event Sourcing


, , . ( ), , . , , — .


— , . , . eventual consistency, , - (« ») .


, , ( , ). - , — .


. eventual consistency, .



:


  • .
  • .
  • ( ).
  • "append only". .
  • FIFO ( ). , .

, . , , :



, . . : , .


(, , ):



:


  • . . , .
  • , . , «», . , , .
  • , . 1% , (. ), , .

:



, Event Sourcing CQRS. , , , , , . , . , , «», , « ». , , (, ). « ».


:


  • : « » : « » « ». , ( , ).
  • - , , , . : request-response, , . , , . : .

Sharding


, event sourcing . - . , :


  • . , / .
  • . - ,


, . , , , . « » , , , , :


  • Event Source ( — ). — id .
  • , ( — , , — , ). , , .
  • ( ).
  • (.. ), .

, , . eventual constistency, , (, , ). , , .


, , :


  • , . .
  • . , Enterprise ( ). sharding . , (, Azure self hosted).
  • — . ( ). — , . , .. , .

Static Content Hosting


, - . : , , , . , ( nginx , , Java-). CDN (Content Delivery Network) , .


— . — , CDN , .


- . ( ), . — , ( ), . — ( , , ) , -. , :


  • URL . file_id + key, key — - , .
  • nginx :
    • . , .
  • : . , , . : IO , . Java , - Rust/C++ . ( ), IO .


( -), . , , , ( ).


( ): Jenkins/TeamCity, , Java. Java-, , . , " / ". : , ( , ), . IO. , , -, . , nginx' ( ).


, :



, . -, . , API .. , , , . ( ), . , , ( ). (- ).


, - . . , . , « », « ». , : , .



. VK Static Content Hosting . - Sharding ( ). Event Sourcing . , , CQRS , . .


, , ( , ). Sharding , , . CQRS - , RX. 10 web . Event Sourcing Apache Kafka. 10 , . Static Content Hosting: - ( , ), .


, , . , , , , , ( ), (, ).


: , , , . , , 100 ( , ..).


All Articles