System Design Primer (Part 1 with Microservice Additions)


A few years ago, to close one of their items, I happened to translate this primer. De facto, this option has become an official translation. But the development of this translation is hindered by the fact that it was written in Google Drive and closed for editing. Today I took the time to reformat all of this text into MD format with the help of the Habr editor, I am happy to publish it here and will soon give it to current contributors.


Dictionary


Node β€” β€”
Content β€” β€” e
Traffic β€” β€” /,
Hardware β€” β€”
Instance β€” β€” . API
Headers β€” β€” ( TCP , HTTP )




(Performance) vs (Scalability)


. , , .


  • , .
  • , , .





(Latency) vs (Throughput)


- .


, .


, .






(Availability) vs () Consistency


CAP



, :


  • β€” , .
  • β€” , . , .
  • β€” , , (node) .

, . .


CP β€” (consistency and partition tolerance) β€” +
, , timeout ( ). . . , -, .


AP β€” (availability and partition tolerance) β€” +
, . ( ), .


, . , .







, . . CAP β€” .



, , . best effort (A best effort approach is taken)


memcached. real-time, VoIP, . , , , .



, , , ( ). .


DNS Email. .



, . , . .


RDBMSes. , .







: .


(Fail-over)


- (Active-passive)
(heartbeats) . , IP .


(downtime) , . (hot) (cold) .


β€” shoot the other node in the head (STONITH), . , , .


- master-slave β€” -.


-
- , , .


, DNS IP . , .


-, β€” master-master β€” -.



  • .
  • , .


Master-slave master-master
.




(Domain name system)



DNS β€” IP . www.example.com 127.0.0.1.


DNS . , DNS . DNS , , - . DNS .


  • NS- (name server) β€” DNS /.
  • MX- (mail exchange) β€” .
  • A- (address) β€” IP .
  • CNAME- (canonical) β€” (example.com www.example.com) A-.

CloudFlare Route 53 DNS . DNS , :



  • β€” ,
    β€”
    β€” A/B

DNS


  • DNS , , .
  • DNS , DNS, .
  • DNS .





(Content delivery network)



Content delivery network (CDN) β€” , . , CDN HTML, CSS, JS, .


CDN :


  • CDN

Push CDN


Push CDNs . , CDN () CDN . .


Push CDN . CDN, .


Pull CDN


Pull CDN . , . CDN- .


TTL β€” time-to-live, . Pull CDN , CDN, , CDN , .


Pull CDN , .


: CDN.


  • CDN , .
  • .

:





(Load balancer)



(, ), , .


:


  • ;
  • ;
  • ;

() HAProxy.


:


  • SSL β€” .
    β€” .
    β€” X.509
  • β€” . , , .

, - - .


:



Layer 4


, . IP , . Network Address Translation (NAT).


Layer 7


, , .


.


4- , , . , .


(Horizontal scaling)


, . ( ). - .


:


  • ,
  • (SQL, NoSQL) (Redis, Memcached)

:


  • , .
  • , .
  • , .





(-) β€” Reverse proxy (web server)



. , .


:


  • β€” , IP , .
  • β€” , .
  • SSL β€” .
  • β€”
  • β€”
  • β€”
    β€” HTML/CSS/JS
    β€”
    β€”
    β€”

vs


  • . , .
  • .
  • NGINX HAProxy layer 7 .

:


  • .
  • . .





/ (Application layer)



. API, .


.


β€” Microservices


, , . API . Pinterest, , : , , , , .


Β«Microservice ArchitectureΒ» . , : -, , (endpoints) .


«» β€” . , , . , , . , . , , , .


, β€” , , , HTTP. - . . .


, , (monolithic style): , . Enterprise : ( HTML javascript-), ( , ) . HTTP , , , HTML , . .


β€” . , , namespace-. . .


, , , . , , . , , . , .



: . , . .


, . , , Unix. , .



, , , , . , , , . , .



, , . , .


, , . : β€” , .


, β€” . , , β€” , - remote procedure call (RPS).


β€” . , , , . , , - , . , - , , , , β€” , .


β€” . Published Interface. . .


, . , , API (coarser-grained), . , - , .


, . , . , , .



, , UI , . , - - . , , . (Conway's Law) .


Β« , - ( ) , Β»
β€” Melvyn Conway, 1967



(Conway's Law)


. , -, , . - , : user-experience, project management.



,


, β€” www.comparethemarket.com. - , .


, . , . , . , - . , . .


?


«» , , «». , , . , « » (, ), .. 12 (. .: , ). , .
, , . , (1 12 1 1 ) , . (. .: , ; , , Β« Β», ).


,


, , , , . .


, , . , " , ", . , , , , .. .


. β€” , . , β€” -.


, , .


(Smart endpoints and dumb pipes)


, . Enterprise Service Bus (ESB). ESB- , , -.


: . , , (decoupled) (cohesive), : Unix- β€” , . , WS-* BPEL, REST- .


β€” HTTP API . Ian Robinson: Β«Be of the web, not behind the webΒ».


, , , (, , Unix). IT-.


β€” . β€” RabbitMQ ZeroMQ . β€” , .


. . «» , . .



. , β€” . . , .


, , . Node.js ? . C++ real-time ? . , ? .


, -, . .


, , . , , -, , . , -. , git github - , - .


Netflix β€” , . , , , . , , .


, . Tolerant Reader Consumer-Driven Contracts , . Consumer-Driven . , . : , β€” YAGNI.


β€” , . , , 24/7. , , . Netflix β€” , . 3 β€” , .


SOA


, , Service Oriented Architecture (SOA), . , .. , SOA. , , , SOA , , , Β«SOAΒ» , , - ESB, .


, SOA ( ESB, , ), .


, , , . Tolerant Reader β€” . β€” β€” , .


SOA , Β«SOAΒ», SOA, , , SOA. , , SOA , , .


,


JVM β€” . , , . , Β« Β» .


, DSL- . , .



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


, , . Bounded Context Domain-Driven Design (DDD). DDD . , , , .


, . , . , , . : , . Polyglot Persistence. Polyglot Persistence , .



, . , . .


, (temporal coupling), , , . , , , (eventual consistency) .


β€” , . , . , , .


, , vs


, , , . HTTP ATOM.


, . , IETF, , open-source .


, , .



. AWS , .


, , Continuous Delivery Continuous Integration. , , . .



Continuous Delivery, . , , . , (automated deployment).


, () . , Continuous Delivery β€” , .


, , β€” . , , , , .



(operations folk). , , . , , β€” open source Netflix, , Dropwizard, .


(Design for failure)


, . - . , . , .. . , , user experience. Simian Army Netflix () .


, . , , , .


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


, .. . .


, . , . , , , , , . , , .


, , . , (/) -: , ..



, (downtime). . : , . , www.guardian.co.uk β€” . Netflix API .



, , () . : , , .


, , . - , , «» ? β€” , . : , , .


- Guardian β€” , , . , , API . , . β€” . . , .


β€” , , . , , . , , . , , .


(granular) . . (redeploy) , . . , , , . , , . , , .


?


, . , β€” , enterprise . , .


β€” Amazon, Netflix, The Guardian, the UK Government Digital Service, realestate.com.au, Forward comparethemarket.com. 2013 , , , , Travis CI. , , , , . ( SOA, , , SOA , , .)


, , β€” . , , , .


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


, - . , . . . , , , , . , . . .


, , . , , .


. , , , . , , , . , .


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


, . , . , , , , , .


β€” Service Discovery


Consul, Etcd, Zookeeper, (, ). Health checks ( ), , HTTP .


: application layer


  • .
  • .







(RDBMS)


SQL
ACID β€”


  • Atomicity β€” .


  • Consistency β€” .


  • Isolation β€” .


  • Durability β€” , .



. - , - , , , , SQL .


- β€” Master-slave replication
, , . , . , .



: master-slave:


  • .

- β€” Master-master replication
. , .



: master-master replication


  • , , .
  • master-master ( ACID), - .
  • , .
  • . : , master-slave, master-master.

:


  • .
  • . , .
  • , .
  • .





β€” Federation



. , . : , , . , . . , .


:


  • .
  • .
  • .


Scaling up to your first 10 million users




// β€” Sharding



. . , , . .


: sharding


  • SQL .
  • . , . .
  • .






. , . (PostgreSQL, Oracle)
, . .


(1000:1), .


:


  • , .
  • . .


Denormalization




SQL


SQL .
.


  • Benchmark β€” .
  • Profile β€” , .


  • MySQL .
  • CHAR VARCHAR .
  • CHAR , VARCHAR, , .
  • TEXT . TEXT . TEXT .
  • INT 2^32 4 .
  • DECIMAL .
  • BLOBS, .
  • NOT NULL .

Use good indices


  • (SELECT, GROUP BY, ORDER BY, JOIN) .
  • B- , , .
  • .
  • , .
  • , .



  • β€” .

  • β€” .





NoSQL


NoSQL - , , . , . NoSQL ACID.


BASE NoSQL. CAP BASE , .


  • Basically available β€” .
  • Soft state β€” .
  • Eventual consistency β€” .

, SQL NoSQL, , NoSQL . .


- β€” Key-value store


: hash table


Key-value store O(1),. , . - .


, in-memory . , , .


- .






/ β€” Document store


: key-value store


XML, JSON, binary . . API .


, , , . , .


MongoDB CouchDB SQL . DynamoDB - .


.






β€” Wide column store



: map ColumnFamily<RowKey, Columns<ColKey, Value, Timestamp>>


β€” . ( SQL).


.






β€” Graph database



: graph


, β€” . , .


, .




All Articles