Concurrency control
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 7 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    How many attempts does optimism need as conflicts rise?

      How many transactions a second can one hot row take?

        Build-up · 6 steps

        From two-phase locking to a deadlock

        Locking makes conflicting transactions wait. Follow the rules that make it serializable, then the failure that waiting creates and the two ways out.

        Step 1 of 6

        Shared and exclusive locks

        Reads take a shared (S) lock, writes an exclusive (X) lock. Readers can share a row, but a writer waits for every holder, and everyone waits for a writer.

        3 interview moments

        You’re the candidate

        The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

        1. Deep dive 1 of 3

          Interviewer

          “Tickets for a final go on sale. In the first minute, thousands of buyers chase the same seat rows. How do you guard each seat?”

          Your move. Pick an approach:

        2. Deep dive 2 of 3

          Interviewer

          “Wallet transfers keep failing with deadlock errors under load. Two code paths lock the same accounts in opposite orders. What do you change?”

          Your move. Pick an approach:

        3. Deep dive 3 of 3

          Interviewer

          “Your PostgreSQL app runs at Serializable, and serialization failures (40001) have jumped. What do you do?”

          Your move. Pick an approach:

        Build-up · 5 steps

        Catch write skew with SSI

        Snapshot isolation’s only rule for writers is first updater wins. Watch two transactions slip past it by writing different rows, and how SSI notices.

        Step 1 of 5

        One snapshot each

        Meera and Kabir supervise a warehouse at night, and at least one must stay on shift. Each starts a transaction, and each snapshot shows 2 on shift.