CoursesSystem design from first principles to design review

Puzzle 14 · 15 of 19

Does the design survive a changed assumption?

Defend a decision, then transfer it to a different domain.

All puzzles in this course

The problem

For a distributed write, mark which replica or store can make the decision. Design the service from a blank sheet. It must handle a concert peak, allocate one last space correctly and resolve an unknown payment result. How can a reviewer distinguish a sound design from a polished diagram?

See it

A visibility deadline meets measured fan-out capacity One post · 2 million followers Entries delivered Promise: visible within 10 s At 10 s: 500,000 delivered 1.5 million still waiting Minimum completion time: 40 s

Scroll sideways to see the full diagram.

  1. A reviewer changes one assumption: a single publisher has two million followers. Suppose visibility requires one stored feed entry for each follower.

    Step 1 of 4
  2. Even if the measured writer devotes all 50,000 entries per second to this post, ten seconds produces only half a million entries.

    One post needs two million feed entries. At 50,000 entries/s, can more queue space meet a 10-second visibility target?

    Step 2 of 4
  3. At the deadline, three quarters of the followers are still missing their entries. More queue space cannot increase write throughput.

    Step 3 of 4
  4. Forty seconds is the best possible completion time at this rate. Try merging this publisher’s recent posts when a reader opens the feed. Now measure the new read cost.

    Step 4 of 4

The building block

For each boundary, name the data, the decision owner, the time budget and the result after a disconnect. Draw the smallest deployment that meets the assumptions. Include a capacity calculation and a measurable trigger for changing the architecture. For each guarantee, propose an experiment that could disprove it. Two successful grants of the same last space would be such a counterexample.

Round one is the parking service. Keep the replies from two contenders and read the winning grant after restart. Round two is assigned seating. Counting remaining tickets is insufficient because two tickets can name the same chair. Enforce uniqueness of event and seat together. Round three is a social feed. Freshness, ordering and read cost matter more than exclusive inventory. Compare building feeds on read with distributing posts at publication time.

Defend a decision under a changed assumption

For a feed with two million followers and a ten-second visibility objective, writing one entry per follower would need 200,000 entries per second for that post alone. Suppose the measured writer sustains 50,000 per second including ordinary work. Even dedicating all of it to this post takes at least 40 seconds. Four times more queue space cannot shorten that lower bound.

A candidate design merges that author's recent posts when a reader opens the feed. State the new cost: feed reads now perform merge work and must enforce current access rights. Test with the actual distribution of follows per reader and a private post revoked between reads. A reviewer can now challenge both the old throughput ceiling and the new read-latency assumption.

Transfer the parking guarantee to numbered seats

A counter can issue two bookings within capacity while assigning both people B12. In this design an active ticket claims one chair at one event. A partial unique index is a rule the database applies only to rows matching its condition. Here that condition is an active ticket.

CREATE TABLE ticket (
  id INTEGER PRIMARY KEY, event TEXT NOT NULL,
  seat TEXT NOT NULL, active INTEGER NOT NULL CHECK (active IN (0, 1))
);
CREATE UNIQUE INDEX one_live_ticket
ON ticket(event, seat) WHERE active = 1;

INSERT INTO ticket VALUES (1, 'Friday', 'B12', 1);
INSERT INTO ticket VALUES (2, 'Friday', 'B12', 1)
ON CONFLICT (event, seat) WHERE active = 1 DO NOTHING;
INSERT INTO ticket VALUES (3, 'Saturday', 'B12', 1);
SELECT id, event, seat FROM ticket WHERE active = 1 ORDER BY id;
SELECT id, active FROM ticket WHERE event = 'Friday' ORDER BY id;

The first table shows active tickets 1 and 3. The second lists every Friday ticket, including any that have ended. Friday's second claim loses, while Saturday is an independent event. Now put the following statement just before the second insert and rerun. Predict which Friday ticket is active and how many Friday rows remain in the table.

UPDATE ticket SET active = 0 WHERE id = 1;

Friday now has two historical rows and one active ticket, number 2. The database retains the old purchase for audit. Defend this choice to a reviewer who proposes uniqueness on seat alone: the same chair is sellable again on Saturday. Then ask what changes for general admission where the promise is a total capacity and tickets have no seat numbers.

Try it

Submit a contract, an estimate with units, a diagram, a failure timeline, a repeatable test and a decision record. Have a reviewer change one assumption: a publisher now has a million followers, or one region loses contact. Predict the result before testing. Explain what measurement would make you change your own decision.

Open the three design cases and grading rubric

Check yourself

What protects an assigned ticket?

Not quite. Two tickets could name the same seat. Re-read that part ↑

Right. Two tickets could name the same seat.

What costs work when distributing a popular post on publication?

Not quite. Each separate recipient list requires work. Re-read that part ↑

Right. Each separate recipient list requires work.

What demonstrates recovery?

Right. A diagram expresses a hypothesis that a drill can test.

Not quite. A diagram expresses a hypothesis that a drill can test. Re-read that part ↑

Sources

What you now know

Defend the user-visible guarantee with a counterexample, a measurement and a changed assumption.

Now hold total capacity fixed. Can changing only the assignment of individual reads cut a driver's wait?