A guest has a listing booked for nights 10 through 14. Another guest asks for night 12 only.

Their dates do not match. The start is different, the end is different. If your check compares check-in to check-in, it waves this booking through.

That is a perfectly reasonable first thing to write. Compare the dates, see they differ, move on. It is also where the bug lives.

The real test is a range test. Two stays clash when each one starts before the other one ends. Night 12 inside a five-night stay fails that test, so that is the test case to write first. If your code passes it, you have the right check. If it does not, you found out from a test instead of on a guest's arrival day.

Then comes the part people skip. Say you read the bookings, decide the nights are free, and write afterward. That is what a working first version looks like, and it holds up fine while one guest at a time is booking.

Now picture two guests asking for the same nights at the same instant. A Service runs the request, and your system can be running many copies of that Service at once. Each copy reads the bookings, and each one sees "free." Each one then writes. Both checks were correct when they ran, and you still have two guests holding the same nights.

The check was honest. It was just old by the time the write happened.

This is where the Relational Database earns its place. It holds your structured rows, and it is the one place every copy of the Service meets. So the check and the write have to be one atomic step in that block: a rule that rejects overlapping date ranges for the same listing. The second insert fails, and the guest sees "those nights are taken."

You do not trust the check you ran a moment ago. You let the write refuse.

This is the part worth keeping. This was never a rule about bookings. It is one question, asked of each rule that must never break: which block is able to enforce this?

A Service cannot, because there are many copies of it and none of them can see the others. The block every copy has to go through is the one that can say no for all of them. The question stays the same and the answer comes from what each block can actually do.

There are ten pieces to ask it with: seven building blocks and three external entities, the User, the External Service and Time. Ten is small enough to hold in your head, and it is enough to ask the question about a system you have never seen. Knowing the blocks this way also helps in system design interviews.

Next time you read a design, pick one rule that must never break and ask it. If the answer is "the code checks first," ask which block would still hold when two copies of that code run at once.

Kay

P.S. Course I teaches the ten pieces one at a time, so the which-block question has an answer when you ask it: https://systemthinkinglab.ai/courses-i-iv.html

This letter goes out by email every Saturday. Subscribe here or read the full archive at systemthinkinglab.ai/newsletters.

If you want to see how products like Instagram and Netflix are designed, take your free 5-day course: the 7 building blocks.