System Design Explorer

Interactive architecture diagrams for common distributed systems

URL Shortener Architecture

0
Requests/sec
0%
Cache Hit Rate
0
DB Ops/sec
0ms
Avg Latency

How it works

A URL shortener must handle 10,000+ reads/sec with low latency. The key insight: reads vastly outnumber writes (100:1 ratio), so we optimize heavily for reads.

Write: hash URL → store in DB Read: check cache → fallback to DB Cache: 99% hit rate target Sharding: by short URL hash CDN: static redirect responses

Social Media Feed Architecture

Fanout on Write (Push)

When a user posts, immediately write the tweet to all followers' feeds. Fast reads, slow writes. Celeb problem: 10M followers = 10M writes per tweet.

Write: O(followers)Read: O(1)Used by: Twitter timeline

Fanout on Read (Pull)

On read, merge feeds from all followed users. Fast writes, slow reads. Scales for celebrities but degrades for active readers following many accounts.

Write: O(1)Read: O(following)Used by: Instagram explore

Consistent Hashing Ring

Why Consistent Hashing?

Traditional modulo hashing (key % N) requires remapping nearly all keys when a node is added/removed. Consistent hashing places both nodes and keys on a ring — only K/N keys need to move when a node changes (where K=keys, N=nodes).

Node add: ~K/N keys moveNode remove: ~K/N keys moveVirtual nodes fix hotspots

Click "Lookup Key" to trace a key lookup through the ring.

CAP Theorem

In a distributed system, you can only guarantee 2 of 3 properties when a network partition occurs.

CP
Consistency + Partition

Returns error or waits if nodes disagree. No stale reads.

HBaseMongoDBRedisZookeeper
AP
Availability + Partition

Always responds, may return stale data. Eventual consistency.

CassandraDynamoDBCouchDBRiak
CA
Consistency + Availability

Works perfectly — until a partition. Then you must choose C or A.

RDBMS (single node)PostgreSQL