Foreign keys
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 · 5 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 long does deleting 1,000 orders take with no child index?

      Build-up · 6 steps

      Two line items, one deadlock

      Two requests on MySQL each add a line to the same order, then bump orders.total. Watch the locks on the order row.

      Step 1 of 6

      Two requests, one order

      Each request adds a line to the same order, then updates orders.total. On MySQL, inserting a line runs a foreign key check on the order row.

      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

        “Customers can close their accounts, and orders reference customers. Which ON DELETE action do you give orders.customer_id?”

        Your move. Pick an approach:

      2. Deep dive 2 of 4

        Interviewer

        “A merchant with 2M orders and 6M order lines leaves the platform. How do you remove their data?”

        Your move. Pick an approach:

      3. Deep dive 3 of 4

        Interviewer

        “Comments can attach to a restaurant, a dish or an order. How do you model the reference?”

        Your move. Pick an approach:

      4. Deep dive 4 of 4

        Interviewer

        “Your MySQL orders data is moving to Vitess shards, and every ALTER must go through gh-ost. Do foreign keys stay?”

        Your move. Pick an approach: