Bugpit

Lessons › From one user to millions

One event, many readers

10,000 req/s and 25% are new orders. Each order must be saved, emailed to the customer and added to analytics. Three Workers do this, but a queue is splitting the orders between them.

Play this level

Free with an account. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

A queue is a to-do list: each job goes to one worker, then it's gone. That's right for sharing work out. It's wrong when three different services each need every order. Here, each one sees only a third of them.

An event stream such as Kafka or Kinesis is a log. It keeps every event, and each reader follows the whole log at its own pace. A new service can start reading without touching the others.

A stream is split into partitions. In Kinesis each one takes 1,000 events per second, and order is only kept inside a partition, so you split by something like order ID.

Readers can fall behind and catch up later. Events stay for 24 hours by default, up to a year if you pay for it, so a slow reader loses nothing. Replaying old events isn't simulated here.

What you have to achieve

10,000 requests a second at the busiest hour, 25% of them writes.

What you learn

Three services now see every order, and none of them knows the others exist. Adding a fourth takes one wire. Open "A day of traffic": each reader falls behind at the evening peak and catches up by midnight, which is why 3 workers handling 1,500 events/s can follow a stream that peaks at 2,500. A real stream would be about 50 minutes behind at its worst.

Check yourself

Three services each need every order. Why not a queue?

Show the answer

A queue gives each job to only one worker. A queue shares work out. A stream keeps every event, and each reader follows the whole log.

A reader falls behind at the evening peak. What happens to the events?

Show the answer

They wait in the stream until it catches up. Events stay for 24 hours by default, so a slow reader catches up later and loses nothing.

Try it yourself

More in From one user to millions

← Stop managing shards Find anything, fast →