AlgoViz

Driving deep dives

easy 30 min

Fifteen minutes, two hard parts.

Video lesson · Chapter 1 of 5

Find an actual risk

0:00 / 4:37

Offer two, finish one

1:20Reel coming soon

Theory

Read or listen first. About 1 min.

What it is

A deep dive is the part of the interview where you look closely at one hard problem: options, a decision, numbers, and what happens when it fails.

You usually have time for two.

Why it exists

The overview shows that you know the parts. Depth shows that you have thought about how they behave.

It is also where levels differ most, so it deserves the largest share of time.

A short history

  1. 1949

    The US military describes failure mode and effects analysis: list how each part can fail and what follows.

  2. 1950s to 1970s

    Toyota's engineers use repeated "why" questions to find root causes.

  3. 2004

    Jesse Robbins starts game days at Amazon, breaking things on purpose to learn.

  4. 2011

    Netflix writes about Chaos Monkey, which stops servers at random.

Words to know

Crux
The part that decides whether the design works.
Failure drill
Walking through a failure and its recovery.
Hot spot
One place with far more load than the rest.
Blast radius
How much is affected when something fails.
Hint
An interviewer's nudge towards something.

How it works

Step through the idea, or press Play.

Step 1 of 3

Find. The part that misses a target or makes this problem different

Understand it

Start here

A diver with limited air

A diver cannot look under every stone. There is air for two good stops and a safe way up. Your interview has air for two deep dives and a summary.

Two stops and a safe way up
100%Air leftAir for two stops

Find it

Where is the hard part?

  1. 1

    Read the targets again

    Which one does the design on the board still miss? That is the first dive.

  2. 2

    Subtract the ordinary

    Take away create, read, update and delete. What is left is the special part: a rush, live data, search, privacy, money.

  3. 3

    Look for many on one

    Many writers on one row, many readers of one key, many reconnects at one moment.

  4. 4

    Ask what is worst if wrong

    Lost money or a child's location beats a slow page.

SystemMisses a targetMakes it differentOffer these two
Library seat booking5,000 readers want 80 seats at 9:00Holds that are never confirmedThe rush, abandoned holds
School bus tracker20,000 parents at 7:45Only the right family may see a stopLive updates, who may watch
Recipe sharingSearch by what is in the kitchenPhotos of every sizeIngredient search, photo pipeline
URL shortenerReads for one viral linkUnique codes from many serversCode generation, hot links
Ride hailing333,000 positions a secondOne driver, two ridersLive positions, matching

Offer it

Two doors, one recommendation

Offering two shows you can see what matters. Recommending one shows you can lead. Asking shows you can listen. It takes one breath.

Minute 25

  1. You

    The whole path works. Two parts deserve depth. One is the rush at 9:00, where thousands want the same 80 seats. The other is a seat that someone holds and never confirms. I would start with the rush, because it decides whether the system survives. Is that where you would like to go?

  2. Interviewer

    Start with the rush, yes.

  3. You

    I will take about seven minutes, then come back for holds.

A good offer

  • Two parts, one sentence each
  • A reason for the first
  • A question at the end
  • A time

A weak offer

  • "What do you want to talk about?"
  • "I could go deeper anywhere."
  • Starting the easy part you rehearsed
  • Five choices

Walk it

From options to a decision

One dive, five moves

Seven minutes, twice

1+2+1+2+1=7,7×2=14≤151 + 2 + 1 + 2 + 1 = 7, \qquad 7 \times 2 = 14 \le 15
State it 1, options 2, choose 1, walk a request 2, break it 1. One minute is left for the turn between dives. It is a guide, not a rule.

Worked example: the 9:00 rush. 5,000 readers want 80 seats in one building. Whatever we build, at least 4,920 of them must be told no.

Most attempts must fail

5,000−805,000=98.4%,5,000200 admitted/s=25 s\frac{5{,}000 - 80}{5{,}000} = 98.4\%, \qquad \frac{5{,}000}{200\ \text{admitted/s}} = 25\ \text{s}
Assume the database serves 200 booking attempts a second with room to spare. A waiting room that admits 200 a second clears the line in 25 seconds.
OptionGradeWhat happens
Lock the whole buildingbreaksOne booking at a time. At 50 ms each, 80 seats take 4 s and everyone else waits or times out
Let all 5,000 try, unique rule decidesworksCorrect. But 98.4% of the load is wasted, and it lands in one second
Waiting room, then the unique rulestrongSame correctness, steady load, a place in the queue for each reader

Walk one request

Place 412 at 200 a second is about 2 seconds. The refusal is part of the design, so show the reader a next step.

Break it

Failure drills with numbers

A failure drill asks four things. What stops? Where does the load go? Who notices? How does it recover? The second one needs a number.

Seat booking: switch off one part at a time

OffThe load goesUsers seeRecovery
Seat map cache5,000 map reads/s fall on the databaseSlow pages, then failed bookingsEach server asks once per building and shares the answer; serve the last map; refuse extra reads
Waiting room5,000 attempts/s reach the serviceErrors at 9:00Admit a fixed number, turn the rest away with a time to retry
Primary database, 30 s300 × 30 = 9,000 attempts fail"Try again" for half a minuteStandby takes over; clients retry with a growing, random wait and the same idempotency key
Email queueEmails wait in a tableA late email, a valid bookingSend from the table when the queue returns

Why retries need care

5,000 requests/s×3 tries=15,000 requests/s5{,}000\ \text{requests/s} \times 3\ \text{tries} = 15{,}000\ \text{requests/s}
If every client retries twice at once, a struggling system gets three times its load. Wait longer each time, add randomness, and cap the tries.

The drill

Bus tracker: the servers restart at 7:45

  1. Interviewer

    You moved to open connections. All the connection servers restart. What happens?

  2. You

    20,000 parents reconnect at once. If they all try in the same second, that is 20,000 sign-in checks in a second. I would have each app wait a random time up to 60 seconds, which is about 333 a second.

  3. Interviewer

    Sixty seconds without a bus, on a school morning?

  4. You

    Fair. Until it reconnects the app asks over plain HTTP every ten seconds, so the position stays within ten seconds. We also restart servers one at a time, so this is the rare case.

Spreading the return

20,00060 s≈333 reconnects/s\frac{20{,}000}{60\ \text{s}} \approx 333\ \text{reconnects/s}

Listen

Reading hints

What they say, what it may mean

  • "Are you sure?"

    Check the last thing you said. There may be a fault, or they want the reason.

  • "What if there are two?"

    Think races: two servers, two requests, the same record.

  • "And at ten times that?"

    Find the first part that breaks, with a number.

  • "Let us come back to this"

    Enough here. Stop and move on.

  • The same question twice

    Your answer missed. Say what you think they are after and check.

  • "Interesting" and silence

    Finish the thought, then ask if they want more.

Lead or follow

Leading and being led

They areYou doYou say
QuietLead: offer, recommend, go"I will start with the rush unless you prefer holds."
SteeringFollow: go there now"Happy to. I will keep holds for later."
Jumping aroundAnswer short, then anchor"Yes, because... Back to the waiting room?"
Going very deepSay what you know and where it ends"I know the idea, not the code. I would expect..."

Following is not a failure. It becomes one only when you go quiet between questions and wait to be pulled. After each answer, add the next step yourself.

Stuck

Getting unstuck

Four ways out

Unstuck, word for word

  1. Interviewer

    Two of your servers hand out the same seat. How?

  2. You

    Let me take the smallest case: two readers, one seat. Both servers read that it is free. Both write. The second write must lose, so checking first is not enough. The decision has to happen in the write itself.

  3. Interviewer

    So?

  4. You

    So the unique rule on seat and slot decides. The loser gets an error, and we show them another seat. No lock between the servers is needed.

Second example

URL shortener: one hot link

  1. 1

    State it

    One link gets 50,000 clicks a second. One key lives on one Redis node.

  2. 2

    Options

    Read the database each time: breaks, one partition. Redis only: works until one key overloads one node. A one-second copy inside each server: strong.

  3. 3

    Choose

    Keep the hottest links in each server for a second. With 20 servers, Redis sees at most about 20 reads a second for that link.

  4. 4

    Cost

    An edit or a takedown may lag a second on top of the edge time. Takedowns also send a purge.

  5. 5

    Break it

    All 20 servers restart empty. The first requests in each share one lookup, so Redis sees about 20 reads, not 50,000.

Summary

The whole topic in one minute.

Find the two parts that matter, offer them, go from options to a decision, then break your own choice with load numbers.

Follow hints. They show where the interviewer wants evidence.

  • Two dives, about seven minutes each, and stop at 40.
  • Offer two, recommend one, ask.
  • Options, choice, one request, one failure.
  • A failure drill asks where the load goes, with a number.
  • A hint is a gift: say it back and follow it.

Sources