Theme

Interactive diagram · architecture

The System Design Primer — a web system at scale

The System Design Primer — a web system at scale A client resolves DNS and can use a CDN. HTTPS traffic passes through a load balancer and web servers to APIs, queues, caches, databases, and object storage. The System Design Primer Diagram after donnemartin/system-design-primer · CC BY 4.0 resolvestatic files HTTPS enqueuepull job read firston miss replicate ClientDNSCDN1 · Front door Load BalancerWeb Server2 · Spread the load Write APIAsyncWrite APIRead API3 · App layer WorkerServiceQueueNoSQL4 · Async work Memory CacheSQL ReadReplicas5 · Fast reads SHARDINGFEDERATIONSQL WriteMaster–SlaveObjectStoreCustomers A–MSQLCustomers N–ZSQLCustomersSQLProductsSQL6 · Store & scale data
✕

1 · Front door

DNS maps the site name to an address. A CDN can serve static files near the client.

✕

2 · Spread the load

A load balancer spreads traffic across web servers. The web layer routes the request to the right application API.

✕

3 · App layer

Read, write, and asynchronous APIs separate work that scales differently. Each API has one clear next hop.

✕

4 · Async work

A queue holds slow work until a worker can pull it. That keeps long-running jobs off the request path.

✕

5 · Fast reads

Read requests check memory first. Read replicas take pressure off the SQL writer when the cache misses.

✕

6 · Store & scale data

The write database replicates to readers, while object storage and split databases scale data handling.

✕

Client

Step 1 · Front door

What it is

The person or program making a request.

Its job here

It starts by resolving a name or requesting static content. Dynamic HTTPS traffic continues to the Load Balancer.

Trade-off

Clients depend on DNS; a DNS outage can stop access even when servers are running.

In the primer

Domain name system →

✕

DNS

Step 1 · Front door

What it is

DNS translates a domain name to an IP address.

Its job here

It receives the client lookup and tells the client where to connect. The client can then reach the CDN or Load Balancer.

Examples

  • CloudFlare
  • Route 53

Trade-off

Accessing DNS adds a slight delay, though caching can reduce it.

In the primer

DNS →

✕

CDN

Step 1 · Front door

What it is

A CDN is a distributed network of proxy servers that serves content close to users.

Its job here

It receives static requests from the Client and serves or fetches files from Object Store. This keeps static work away from Web Server.

Examples

  • CloudFlare

Trade-off

Content can be stale when it changes before its TTL expires.

In the primer

Content delivery network →

✕

Load Balancer

Step 2 · Spread the load

What it is

A load balancer distributes incoming requests across computing resources.

Its job here

It receives HTTPS traffic from the Client and sends it to Web Server instances. Multiple instances avoid one machine carrying all traffic.

Examples

  • HAProxy
  • NGINX

Trade-off

A load balancer can become a bottleneck if it lacks resources or is configured poorly.

In the primer

Load balancer →

✕

Web Server

Step 2 · Spread the load

What it is

A reverse proxy centralizes internal services behind one public interface.

Its job here

It receives traffic from Load Balancer and routes it to the APIs. It can also serve cached or static content.

Examples

  • NGINX
  • HAProxy

Trade-off

A single reverse proxy is a single point of failure; failover adds complexity.

In the primer

Reverse proxy (web server) →

✕

Worker Service

Step 4 · Async work

What it is

A worker runs jobs outside the request path.

Its job here

It pulls a job from Queue and can update NoSQL or store output in Object Store. This keeps slow work away from the client request.

Examples

  • Celery

Trade-off

Queues can add delays and complexity.

In the primer

Asynchronism / task queues →

✕

Queue

Step 4 · Async work

What it is

A message queue receives, holds, and delivers jobs.

Its job here

Write API Async enqueues work here. Worker Service pulls the next job and processes it in the background.

Examples

  • Redis
  • RabbitMQ
  • Amazon SQS

Trade-off

Queues can add delays and complexity.

In the primer

Asynchronism / message queues →

✕

Write API Async

Step 3 · App layer

What it is

An application API that accepts work that can finish later.

Its job here

It receives work from Web Server and hands a job to Queue. Worker Service handles that job outside the request.

Trade-off

Queues add delays and complexity for work that would be inexpensive to run synchronously.

In the primer

Application layer →

✕

Write API

Step 3 · App layer

What it is

An application API that handles writes.

Its job here

It receives write requests from Web Server and sends changes to SQL Write Master–Slave. It can also store files in Object Store.

Trade-off

Loosely coupled services add deployment and operations complexity.

In the primer

Application layer →

✕

Read API

Step 3 · App layer

What it is

An application API that handles reads.

Its job here

It receives requests from Web Server and checks Memory Cache first. On a miss it reads from SQL Read Replicas.

Trade-off

Loosely coupled services add deployment and operations complexity.

In the primer

Application layer →

✕

Memory Cache

Step 5 · Fast reads

What it is

An in-memory cache holds key-value data in RAM.

Its job here

Read API checks it first. On a miss, Read API reads from SQL Read Replicas instead. This takes load off the database.

Examples

  • Memcached
  • Redis

Trade-off

Cache invalidation is difficult and adds complexity.

In the primer

Cache →

✕

NoSQL

Step 4 · Async work

What it is

A NoSQL database stores data outside the relational model.

Its job here

Worker Service can update it after pulling a job from Queue. It accepts data that does not need the SQL write path.

Examples

  • MongoDB
  • DynamoDB
  • Cassandra

Trade-off

NoSQL systems often trade strong consistency for availability or partition tolerance.

In the primer

NoSQL →

✕

SQL Write Master–Slave

Step 6 · Store and scale data

What it is

A master serves writes and replicates them to slaves.

Its job here

Write API sends writes here. Changes replicate to SQL Read Replicas, which serve read traffic.

Examples

  • MySQL

Trade-off

A master failure before replication can cause data loss.

In the primer

Master-slave replication →

✕

SQL Read Replicas

Step 5 · Fast reads

What it is

Read replicas serve reads after changes are copied from the write master.

Its job here

Read API sends cache misses here. The replicas reduce load on SQL Write Master–Slave.

Examples

  • MySQL

Trade-off

More replicas can mean greater replication lag.

In the primer

Master-slave replication →

✕

Object Store

Step 6 · Store and scale data

What it is

Object storage keeps static files separately from application servers.

Its job here

CDN serves static files from it, while Write API and Worker Service can store new files there. This removes that content from Web Server storage.

Examples

  • S3

Trade-off

Separate storage increases complexity and requires application changes.

In the primer

Scaling AWS walkthrough →

✕

Sharding

Step 6 · Store and scale data

What it is

Sharding distributes one data set across databases, each holding a subset.

Its job here

Customers A–M and Customers N–Z show a split by data range. Application logic chooses the shard for each read and write.

Trade-off

You need to update application logic to determine which shard to read and write.

In the primer

Sharding →

✕

Federation

Step 6 · Store and scale data

What it is

Federation splits databases by function.

Its job here

Customers SQL and Products SQL keep different functions separate. The application chooses the database for each operation.

Trade-off

Joining data from two databases is more complex.

In the primer

Federation →

←/→ step · Space play/pause · R replay · Home/End jump

Detail · follows playback, or click any box or step to pin it

Click any box for an explanation, or use Next or Play to walk through the six steps.

1 · Front door

DNS maps the site name to an address. A CDN can serve static files near the client.

The client enters through DNS or the CDN.

2 · Spread the load

A load balancer spreads traffic across web servers. The web layer routes the request to the right application API.

Requests are distributed before they reach the application.

3 · App layer

Read, write, and asynchronous APIs separate work that scales differently. Each API has one clear next hop.

The API layer separates read, write, and deferred work.

4 · Async work

A queue holds slow work until a worker can pull it. That keeps long-running jobs off the request path.

Queued work is processed without blocking the request.

5 · Fast reads

Read requests check memory first. Read replicas take pressure off the SQL writer when the cache misses.

The read path favors memory and then replicas.

6 · Store and scale data

The write database replicates to readers, while object storage and split databases scale data handling.

Storage patterns keep growing data manageable.