News site: every view counted
A news site gets 30,000 req/s on a big news day. Half are images. A third of the rest are page view events, and editors want a live "trending now" list and a full report every morning. Every event is written to the main database.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Analytics is the classic case of data that's written once and read in bulk later. It doesn't belong in the database that serves pages.
Send each view down an event stream. One reader keeps live counts, like the top stories over the last 10 minutes. That's a Stream Processor.
Another reader loads everything into a Data Warehouse, where analysts can run huge queries without slowing the site. Its data is a little behind, and that's fine for a report.
Images go on a CDN, as always. On a news day they're most of your traffic.
What you have to achieve
30,000 requests a second at the busiest hour, 15% of them writes and 50% static files.
- No broken or illegal connections
- Use a CDN
- Use a Stream Processor
- Use a Data Warehouse
- No component is overloaded
- Workers clear the queue within the day
- Fewer than 0.1% of requests fail
- p99 response time under 250 ms
What you learn
The site now serves readers, editors and analysts, and none of them slows the others down. Watch the data warehouse line on the bill: storing every event forever adds up, which is why teams keep raw events for a while and summaries for longer.
Check yourself
Where should the morning report's huge queries run?
- On the database that serves pages
- In a Data Warehouse
- On the CDN
Show the answer
In a Data Warehouse. A warehouse is a little behind, and analysts can't slow the site down there.
What builds the live "trending now" list?
- A Stream Processor counting views as they flow past
- A nightly job
- The cache
Show the answer
A Stream Processor counting views as they flow past. It keeps running counts over a window, like the last 10 minutes.