Two arrows converging on a single 10:15 slot with a lock above it and a one winner, zero duplicates badge.

    Two taps, one queue: how DrInCity handles retries and races

    Idempotency keys, versioned writes and one transaction under a per-doctor lock. How a live queue survives double taps, lost responses and simultaneous clicks.

    GC
    GarunaCDX Editorial
    Editorial team
    Nov 22, 2026 4 min read
    Key takeaways
    • An idempotency key makes a retried booking return the first answer, not make a second booking.
    • A version on every write means a stale screen loses cleanly instead of overwriting.
    • Many small writes with correct guards can still tear a queue. Use one transaction.
    • Emergency insert and queue advance take the same lock, so they queue up and never collide.
    • The pass condition for a race test is exactly one winner and positions one to N with no gaps.

    DrInCity series · The engineer’s view

    Quick answer

    A booking has to survive a double tap, a lost response and two staff pressing the same button. DrInCity uses an idempotency key for retries, a version on every write for conflicts, and one transaction under a per-doctor lock for anything that renumbers a queue, then tests with concurrent races and not single clicks.

    The short answer

    A booking has to survive a double tap, a lost response and two staff pressing the same button. Use an idempotency key for retries, a version on every write for conflicts, and one transaction under a per-doctor lock for anything that renumbers a queue. Then test with races, not single clicks.

    Three ways a queue breaks

    What happensWithout a guardThe guard
    The same request arrives twice (flaky network, impatient thumb)Two bookingsIdempotency key
    Two people change one row togetherThe later write silently winsVersion on every write
    A change touches many rows and fails halfwayA queue with duplicates and gapsOne transaction under a lock

    We wrote a generic version of this in how to stop double bookings. Here is the DrInCity version.

    Retries

    A sequence diagram: a phone books a slot, the response is lost, the phone retries with the same key, and gets the original booking back.
    A retry that cannot double-book. The same request, sent twice, produces one booking.

    The phone sends a key with every booking. The function claims the key and takes the slot in the same database call. If the response is lost and the phone retries, the key is already marked done, so it returns the first answer. One booking, two requests, no drama.

    Booking runs as a single round trip to the database: check the role, check the payment gate, check the doctor’s window, build the day’s slots once, take the slot, complete the key. Fewer round trips means fewer places to fail between steps.

    Slots are 15 minutes with room for one booking each. If two patients grab the same slot, exactly one wins and the other gets a clean message. A patient who already holds the slot gets it back instead of being told it is full.

    Conflicts

    Every write to a queue row carries the version the screen last saw. If someone else has moved the row since, the write is refused and the screen reloads. A receptionist who taps End on a stale screen loses cleanly. They never overwrite a newer truth.

    Torn writes

    This is the one that surprised us.

    Advancing the queue touches every row behind the patient being finished. We first wrote it as many small writes, each guarded individually. Each guard was correct. Together they were useless: a failure halfway left the first rows renumbered and the rest not, and a retry could not repair it, because the retry no longer saw the state it expected.

    Left: a write per row leaves some patients on old positions after a failure. Right: one transaction under a lock commits everything or nothing.
    Many small writes, or one transaction. How it commits is the whole difference.

    Our own review found this, not a clinic. The fix moved the whole advance into one transaction, under a lock per doctor’s queue. The emergency insert takes the same lock, so an emergency and an End tapped in the same second queue up behind each other instead of colliding.

    The same review found a second bug, older: an emergency insert placed the patient at position one even when a consultation was in progress, producing two patients at position one. The emergency patient now goes immediately after the consultation in progress, which is what the original design intended.

    What we test to prove it

    Dozens of simultaneous writers on one slot. An advancer racing emergency inserts. A forced overlap on the lock. The pass condition is not “no error”, it is “exactly one winner and positions run one to N with no gaps”. That is the next article: break it before a clinic does.

    What we don’t claim

    We designed for peak hours and tested for them on our own harness. We publish no load figures, and we write “not verified” in our notes next to anything we have not seen run for real. If a vendor tells you a booking system is concurrency-safe, ask to see the race test.

    Concurrency review
    Send us your booking or queue logic. We will tell you what happens when two people press the button at once.
    Book a review

    The retry, version and transaction patterns, and the two bugs found in our own review, come from DrInCity’s migration notes and test harnesses. The advance fix is deployed. No load or latency figures are published. Pattern-level detail only, by design.

    Your verdict
    Was this article useful?
    GC
    Written by
    GarunaCDX Editorial
    Editorial team

    Engineers, product and growth folks at GarunaCDX writing about the systems we build for clients.

    View all articles
    Share
    Planning something similar?

    Let's talk about your build.

    Tell us what you are building. A founding engineer replies within one working day with how we would approach it.

    FAQ

    Frequently asked questions

    A unique value sent with a request. If the same key arrives again, the server returns the first result and does nothing new, so a retried booking cannot become two.

    Queues for different doctors never interact, so locking per doctor keeps them from waiting on each other. Everything that renumbers one doctor's queue takes the same lock.

    No. Our own review found it, and the fix is deployed. We describe it so you can ask any vendor whether their last review found something like it.

    No. We tested on our own harness and we say what we have not verified. Treat a vendor who publishes capacity claims without a test as a risk.

    The GarunaCDX build log

    Industry insights, once a month

    New case studies, healthcare, marketplace, B2B SaaS and industrial breakdowns, and the engineering notes behind what we ship. One short email a month, no fluff.

    We never share your data — see our Privacy Policy for details.