Bugpit

Lessons › Big architectures

Smart home: a million devices

A million thermostats and plugs report in every few minutes: 4,000 req/s at the evening peak, 80% of them readings. Every reading lands in the main database, and the nightly energy report runs at 20:00, on top of the peak.

Play this level

Part of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

Device readings are nearly all new writes, and old values never change. A time-series database is built for exactly that, and keeps them out of the database the app needs.

Put the readings on an event stream first. Devices come and go in bursts, and the stream gives each burst a place to wait while workers save it.

The nightly report is the other half. A scheduler starts it at a set hour, and someone set it to the busiest hour of the day. At 03:00 traffic is a small fraction of the peak.

Check every hour of the day, not just the peak. A design that holds at 20:00 can still fall over at 21:00 if something else starts then.

What you have to achieve

4,000 requests a second at the busiest hour, 80% of them writes.

What you learn

The database went from drowning to calm, and the report costs nothing more: it just runs at night. Most "we need bigger machines" moments start with work in the wrong place or at the wrong time.

Check yourself

Why do device readings belong in a Time-Series DB?

Show the answer

They're nearly all new writes that never change. A time-series store is built for that pattern, and keeps it away from the database the app needs.

The nightly report broke the evening. What fixed it for free?

Show the answer

Running it at 03:00. Same job, same machines. At 03:00 traffic is a small fraction of the peak.

Try it yourself

More in Big architectures

← Game leaderboard: 2 million players News site: every view counted →