<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jason Michael</title>
    <description>The latest articles on DEV Community by Jason Michael (@builtbyjason).</description>
    <link>https://dev.to/builtbyjason</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4066352%2Fcbb30880-2b1c-47a8-b6ec-793ffb57873f.jpg</url>
      <title>DEV Community: Jason Michael</title>
      <link>https://dev.to/builtbyjason</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/builtbyjason"/>
    <language>en</language>
    <item>
      <title>Korum: Detect-and-Refund vs. Prevent — A Concurrency Tradeoff</title>
      <dc:creator>Jason Michael</dc:creator>
      <pubDate>Thu, 06 Aug 2026 18:44:40 +0000</pubDate>
      <link>https://dev.to/builtbyjason/korum-detect-and-refund-vs-prevent-a-concurrency-tradeoff-1250</link>
      <guid>https://dev.to/builtbyjason/korum-detect-and-refund-vs-prevent-a-concurrency-tradeoff-1250</guid>
      <description>&lt;p&gt;&lt;em&gt;Why I Didn't Try to Make Double-Booking "Impossible" — I Made It Cheap to Reverse&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A common instinct when building any capacity-constrained booking system (event slots, appointment times, seats) is to reach for a hard database constraint that makes overbooking structurally impossible. I want to walk through why I didn't do that for Korum, and what I built instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Korum coordinates casual sports matches. A match has a fixed capacity. When it's full, further joins should fail cleanly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "impossible" would actually require
&lt;/h2&gt;

&lt;p&gt;Making concurrent overbooking truly impossible under high contention generally means serializing writes at the database level — something like a unique constraint on a (match_id, slot_number) pair with slot numbers assigned atomically, or row-level locking on the match capacity row during the write. Both are legitimate approaches. Both also add real complexity: lock contention under load, or careful slot-assignment logic that has to be right in every code path that touches it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built instead
&lt;/h2&gt;

&lt;p&gt;Application code performs a capacity check before creating a payment hold — a soft check, not a guarantee. The actual enforcement happens through database routines that confirm a paid participant atomically; if an overflow case slips through the soft check anyway, it's caught at confirmation time and the payment is marked for refund review, rather than silently accepted as a valid booking.&lt;/p&gt;

&lt;p&gt;In plain terms: overbooking isn't prevented from ever occurring — it's detected immediately after, and reversed, rather than left for someone to discover manually later (e.g., a captain finding 12 confirmed players for an 11-player match on Sunday morning).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this tradeoff, specifically
&lt;/h2&gt;

&lt;p&gt;The cost of a failure matters as much as the probability of it. In this domain, the failure mode of "briefly overbooked, then refunded" is low-cost: an apology, a refund, and a fix, versus the engineering cost of building and maintaining stricter locking for what's a genuinely rare race condition given realistic traffic patterns for a weekend-sports coordination app.&lt;/p&gt;

&lt;p&gt;I'd build this differently for something with a higher failure cost — a single-seat airline booking, say, where "sorry, we double-sold your seat" isn't an acceptable outcome even rarely. For Korum, detect-and-refund is the right tradeoff.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other half: idempotent webhook handling
&lt;/h2&gt;

&lt;p&gt;Payment confirmations arrive via a Razorpay webhook, and webhooks aren't guaranteed exactly-once — network retries can cause the same event to fire more than once. The handler verifies incoming signatures and writes confirmations in a way designed to be safe under repetition: a duplicate delivery of the same event doesn't produce a duplicate effect.&lt;/p&gt;

&lt;p&gt;Curious how others have reasoned about prevention vs. detection-and-recovery tradeoffs for similar capacity-constrained systems — particularly where the "acceptable failure cost" line sits for you.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>database</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
