<?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: Deepak kumar</title>
    <description>The latest articles on DEV Community by Deepak kumar (@deepak_kumar_e0700e0a26e9).</description>
    <link>https://dev.to/deepak_kumar_e0700e0a26e9</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3583866%2F5d6397ce-f77b-4b5b-9741-0e9048615b88.jpg</url>
      <title>DEV Community: Deepak kumar</title>
      <link>https://dev.to/deepak_kumar_e0700e0a26e9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deepak_kumar_e0700e0a26e9"/>
    <language>en</language>
    <item>
      <title>💺 The Real Reason Scalable Booking Systems Don’t Update Seat Tables Directly</title>
      <dc:creator>Deepak kumar</dc:creator>
      <pubDate>Sun, 26 Oct 2025 19:26:00 +0000</pubDate>
      <link>https://dev.to/deepak_kumar_e0700e0a26e9/the-real-reason-scalable-booking-systems-dont-update-seat-tables-directly-4ed6</link>
      <guid>https://dev.to/deepak_kumar_e0700e0a26e9/the-real-reason-scalable-booking-systems-dont-update-seat-tables-directly-4ed6</guid>
      <description>&lt;p&gt;When designing systems like BookMyShow or airline ticketing, it’s tempting to say: &lt;br&gt;
*&lt;em&gt;👉 “Let’s just mark the seat as booked in the seat table.”&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
But at scale, this design creates lock contention and data inconsistency that’s hard to recover from ⚠️&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;🚨 Problem: When Seat Table Becomes the Source of Truth&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
1️⃣ Locking &amp;amp; Scaling Issues Every user booking the same show updates the same few seat rows. Thousands of concurrent writes → row-level locks → DB slowdown. Horizontal scaling doesn’t help since all writes hit the same records. Even reads (seat map views) get blocked by locks — the system becomes sluggish.&lt;/p&gt;

&lt;p&gt;2️⃣ Inconsistency in Payment Flow&lt;br&gt;
When seat status and booking/payment updates are tightly coupled, several failure scenarios appear 👇&lt;/p&gt;

&lt;p&gt;Case 1: Payment Fails, Seat Marked Booked&lt;br&gt;
User clicks “Book” → seat immediately marked as booked in the seat table&lt;br&gt;
Payment fails ❌ → seat remains blocked temporarily or until a manual refresh / cleanup runs&lt;br&gt;
System shows fewer available seats even though no booking exists&lt;/p&gt;

&lt;p&gt;Case 2: Payment Succeeds, Seat Not Updated&lt;br&gt;
Payment succeeds 💰 → booking entity created successfully&lt;br&gt;
But due to network or DB error, seat status never updated in seat table&lt;br&gt;
Other users still see the seat as available → possible double booking&lt;/p&gt;

&lt;p&gt;Case 3: Race Condition&lt;br&gt;
Two users read the same seat as available simultaneously&lt;br&gt;
Both try to book → without atomic locking, both transactions may partially succeed&lt;br&gt;
System ends up with inconsistent seat states&lt;/p&gt;

&lt;p&gt;👉 Result: Ghost bookings, double bookings, and blocked seats — classic data inconsistency&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;⚙️ The Scalable Solution — Two-Layer Architecture&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
1️⃣ Source of Truth (Booking Table → CP System)&lt;br&gt;
Stores all confirmed bookings and payments.&lt;br&gt;
ACID transactions ensure each booking is uniquely tied to one seat.&lt;br&gt;
Guarantees correctness and durability.&lt;/p&gt;

&lt;p&gt;However, if we rely only on this table for seat availability queries, every user request must scan booking records — adding latency and increasing DB load during high traffic.&lt;/p&gt;

&lt;p&gt;2️⃣ Fast Read Layer (Seat Availability Cache → AP System)&lt;br&gt;
A separate, high-speed cache (Redis / in-memory store) built for quick lookups.&lt;br&gt;
Stores the current state of each seat (available/booked/locked).&lt;br&gt;
Used by the seat map or search APIs to serve instant responses, even during heavy load.&lt;br&gt;
Updated asynchronously from booking events.&lt;/p&gt;

&lt;p&gt;This dual-layer design ensures the write path stays consistent (CP) while the read path stays blazing fast (AP).&lt;/p&gt;

&lt;p&gt;⚡ Event-Driven Sync (Eventual Consistency)&lt;br&gt;
After successful booking, an event SeatBooked → published to Kafka / Queue.&lt;br&gt;
Cache listener updates seat status → other users see instant change.&lt;br&gt;
A few milliseconds of delay is okay — eventual consistency guarantees converge.&lt;/p&gt;

&lt;p&gt;⏳ Temporary Seat Locking&lt;br&gt;
When user starts payment → lock seat in Redis for 2–3 minutes.&lt;br&gt;
Lock auto-expires if payment fails.&lt;br&gt;
Prevents double booking under massive concurrency.&lt;/p&gt;

&lt;p&gt;✅ Final Result&lt;br&gt;
Booking table → Strong consistency (CP)&lt;br&gt;
Cache → High availability (AP) &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Combined → Scalable, fault-tolerant design ready for millions of user🚀 &lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
🎥 I’ve explained this concept in detail with architecture diagrams in my latest video — check it out here 👇 &lt;br&gt;
🔗 &lt;a href="https://lnkd.in/ggkswiQA" rel="noopener noreferrer"&gt;https://lnkd.in/ggkswiQA&lt;/a&gt;&lt;/p&gt;

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