Idempotency
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 much storage do idempotency keys need?

      How many double charges does a fresh key per retry cause?

        Can two clients’ random UUID keys collide?

          Build-up · 6 steps

          Survive a crash mid-charge

          A checkout that charges a card can’t be one database transaction. Split it into atomic phases with recovery points, and a retry resumes where the last attempt stopped.

          Step 1 of 6

          Claim the key

          tx1 inserts key K as in progress and commits the recovery point started. Each box is one local database transaction.

          4 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 4

            Interviewer

            “A fitness app syncs each day’s step count, and sync retries are common. How do you write it?”

            Your move. Pick an approach:

          2. Deep dive 2 of 4

            Interviewer

            “POST /orders assigns a fresh ID every time, so retries create duplicate orders. What’s the cheapest fix?”

            Your move. Pick an approach:

          3. Deep dive 3 of 4

            Interviewer

            “To stop duplicate payments, a teammate suggests rejecting any request whose body hash was seen recently. Do it?”

            Your move. Pick an approach:

          4. Deep dive 4 of 4

            Interviewer

            “Payments live in PostgreSQL. The team wants the idempotency keys in Redis for speed. Your call?”

            Your move. Pick an approach: