
Design Twitter for Millions of Users
A microblogging platform with tweet ingestion, hybrid fan-out timelines, typeahead search, and real-time notifications.
Asynchronous event producers and consumers connected through a message broker for decoupled communication.
Rough, order-of-magnitude numbers. The point is to justify the architecture, not to be exact.
A diagram shows what exists; a trace shows what happens. Press play on a flow, or click any step, and the diagram above lights up the exact path that request takes.
From a client action to two independent consumers reacting in parallel.
What happens when one event can never be processed successfully.
Every box on the canvas, and the job it does. Click a card to locate it in the diagram; click the node itself for the full deep dive.
In a request-driven system, a producer that wants two things to happen must call both directly — and now depends on both being available. Event-Driven Architecture breaks that dependency: a producer publishes a fact about what already happened, and any number of consumers react to it independently, without the producer ever knowing they exist.
The Message Broker is a durable, partitioned log, not a transient mailbox. Every event a producer publishes is retained for a fixed window (7 days here), which means:
Consumer A and Consumer B in this diagram both subscribe to the same events but belong to different consumer groups, so the broker delivers every event to both. Each writes its own resulting state, shaped for its own purpose — this is what makes it safe to keep adding consumers without ever touching the producer.
Decoupling isn't free. Delivery is at-least-once, so consumers must tolerate duplicate processing. Ordering is only guaranteed within a partition, so anything that depends on strict global order needs its partition key chosen carefully. And a message that can never be processed successfully needs somewhere to go besides an infinite retry loop — which is exactly what the dead-letter queue is for.
An architecture is a record of trade-offs. For every major choice here: what won, what lost, and why the constraints made it so.
With 10+ consumer groups and growing, direct calls would mean every new feature requires a code change and a redeploy of the producer. Publishing an event once lets any number of consumers subscribe — including ones that don't exist yet — with zero changes to the producer.
Retention means a consumer added next month can replay the last 7 days of history instead of starting blind. Consumer groups mean Consumer A and Consumer B can both process every event independently — a plain queue would hand each message to only one of them.
Coupling consumers to a shared writer reintroduces the exact coordination cost events were meant to remove — a schema change for one consumer risks breaking another. In this diagram they share one database for simplicity; at larger scale each consumer typically owns its own datastore entirely.
Retrying forever lets one malformed event stall an entire partition behind it; dropping it silently loses data with no trace. A DLQ (see the poison-message flow) keeps the main stream moving while giving an operator a concrete queue to inspect, fix, and replay from.
Reading a system means sensing where it cracks under 10× load. These are the pressure points of this design, and how it holds.
If the broker accepts events faster than a consumer can process them, its backlog grows continuously. Downstream state falls further and further behind — sometimes past the point where it's still useful.
Autoscale consumer instances against a lag metric, not CPU, and set partition count as the hard ceiling on parallelism — the consumer lag alert at >10s is the signal that catches this before it's visible to users.
Kafka-style brokers guarantee order only by processing a partition's messages sequentially. A message the consumer can never successfully process would otherwise stall every message queued behind it in that partition indefinitely.
The dead-letter queue (see the poison-message flow) removes the offending message after the retry budget is exhausted, letting the partition continue while the bad message waits for manual inspection.
Broker redelivery on failure, timeout, or consumer-group rebalance means the same event can reach a consumer more than once. A consumer that isn't expecting this will double-apply the side effect.
Consumers key writes by the event's unique ID and make the write idempotent (upsert instead of insert-only), so processing the same event twice produces the same end state as processing it once.
Two events for the same entity that land in different partitions can be processed out of order — a 'cancel' could be processed before the 'create' it depends on.
Choose a partition key derived from the entity ID itself, so every event for the same entity always lands in the same partition and is processed strictly in order relative to each other.
If you can answer these without scrolling back up, the architecture is yours. Try each one out loud before revealing.
Every great system starts as a sketch on a whiteboard. The ability to zoom out and see the whole picture (how services connect, where data flows, what breaks and why) is what separates engineers who build features from engineers who build systems. This diagram is more than boxes and arrows. It's a map of decisions, trade-offs, and intentional design.
Studying architectures isn't just about passing interviews. It's about training your intuition. The more systems you take apart, the better you get at sensing where a monolith will crack, where a queue belongs, or when a cache is hiding a deeper problem. You start seeing patterns instead of chaos.
So keep reading, keep tracing those edges, keep asking "why this way and not that way." The engineers who truly understand large systems are the ones who never stop being curious about how things fit together. That curiosity is the only ingredient that really matters.
Atharva Arbat@arbat_atharva

A microblogging platform with tweet ingestion, hybrid fan-out timelines, typeahead search, and real-time notifications.
A scalable, highly available cloud file storage and synchronization service.
Cloud-native e-commerce platform on AWS