<?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: Hokutoman00</title>
    <description>The latest articles on DEV Community by Hokutoman00 (@hokutoman00).</description>
    <link>https://dev.to/hokutoman00</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%2F3995590%2Fdb8c4859-51e7-4855-97df-ca3932c09b7e.jpg</url>
      <title>DEV Community: Hokutoman00</title>
      <link>https://dev.to/hokutoman00</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hokutoman00"/>
    <language>en</language>
    <item>
      <title>Building on Aurora DSQL multi-region: the setup notes I wish I'd had</title>
      <dc:creator>Hokutoman00</dc:creator>
      <pubDate>Sun, 21 Jun 2026 17:46:09 +0000</pubDate>
      <link>https://dev.to/hokutoman00/building-on-aurora-dsql-multi-region-the-setup-notes-i-wish-id-had-3d4m</link>
      <guid>https://dev.to/hokutoman00/building-on-aurora-dsql-multi-region-the-setup-notes-i-wish-id-had-3d4m</guid>
      <description>&lt;p&gt;I built WorldSeat — a worldwide ticket on-sale that sells one seat to exactly one fan — on &lt;strong&gt;Aurora DSQL&lt;/strong&gt; running active-active across two AWS regions. DSQL gave me the one property the whole app depends on: serializable isolation, so naive read-then-write code stays correct under a simultaneous global stampede. Here are the concrete, load-bearing details that aren't obvious from the headline, written down so the next builder spends those hours elsewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A multi-region cluster needs a &lt;em&gt;witness&lt;/em&gt; region, and starts life PENDING
&lt;/h2&gt;

&lt;p&gt;You don't just flip a "multi-region" switch. You create one cluster per active region and bind them with a third &lt;strong&gt;witness&lt;/strong&gt; region that holds no endpoint but participates in the quorum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# region A (active), declaring the witness&lt;/span&gt;
aws dsql create-cluster &lt;span class="nt"&gt;--region&lt;/span&gt; us-east-1 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--multi-region-properties&lt;/span&gt; &lt;span class="s1"&gt;'{"witnessRegion":"us-west-2"}'&lt;/span&gt;
&lt;span class="c"&gt;# -&amp;gt; status: PENDING_SETUP&lt;/span&gt;

&lt;span class="c"&gt;# region B (active), same witness&lt;/span&gt;
aws dsql create-cluster &lt;span class="nt"&gt;--region&lt;/span&gt; us-east-2 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--multi-region-properties&lt;/span&gt; &lt;span class="s1"&gt;'{"witnessRegion":"us-west-2"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each cluster comes up &lt;strong&gt;PENDING_SETUP&lt;/strong&gt; and stays there until you peer them. They do not become &lt;code&gt;ACTIVE&lt;/code&gt; on their own — that surprised me, and it's the first place to look if a cluster seems stuck.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Peering is a mutual, per-ARN permission
&lt;/h2&gt;

&lt;p&gt;You update each cluster to add the other as a peer ARN. The gotcha: &lt;code&gt;dsql:AddPeerCluster&lt;/code&gt; is authorized &lt;strong&gt;per peer ARN&lt;/strong&gt;, so your IAM policy has to allow the action against the specific cluster ARNs you're peering, not just &lt;code&gt;dsql:*&lt;/code&gt; on a wildcard you forgot to include. Once both sides reference each other, both flip to &lt;code&gt;ACTIVE&lt;/code&gt;. Connect to each &lt;em&gt;regional&lt;/em&gt; endpoint; the witness region has none.&lt;/p&gt;

&lt;p&gt;The full IAM set I needed, beyond the default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dsql:CreateCluster  dsql:GetCluster  dsql:UpdateCluster
dsql:AddPeerCluster dsql:DeleteCluster dsql:ListClusters
dsql:DbConnect      dsql:DbConnectAdmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Auth is an IAM token, not a stored password
&lt;/h2&gt;

&lt;p&gt;DSQL speaks the PostgreSQL wire protocol on port 5432, but you don't manage a password. You mint a short-lived IAM auth token at connect time and hand it to your Postgres driver as the password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Pool&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DsqlSigner&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@aws-sdk/dsql-signer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;signer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DsqlSigner&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;region&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;credentials&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;signer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDbConnectAdminAuthToken&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pool&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5432&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;postgres&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;ssl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;rejectUnauthorized&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;idleTimeoutMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;connectionTimeoutMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a serverless deployment (mine runs on Vercel Route Handlers) I mint a fresh pool per request and bound &lt;code&gt;max&lt;/code&gt; to the burst size, so a "fire 60 buyers at one seat" test maps to a controlled number of real connections.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. DDL has no BEGIN wrapper — each statement is its own transaction
&lt;/h2&gt;

&lt;p&gt;Coming from vanilla Postgres I tried to wrap schema creation in a transaction. DSQL runs each DDL statement as its own implicit transaction, so just issue them directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`CREATE TABLE IF NOT EXISTS seats (
  seat_id TEXT PRIMARY KEY, status TEXT NOT NULL, owner TEXT, sold_at TIMESTAMPTZ)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`CREATE TABLE IF NOT EXISTS op_log (
  id TEXT PRIMARY KEY, seat_id TEXT, buyer TEXT, outcome TEXT,
  attempts INT, t_start DOUBLE PRECISION, t_end DOUBLE PRECISION)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. The OCC retry loop is the whole point — write it on purpose
&lt;/h2&gt;

&lt;p&gt;DSQL enforces serializability with optimistic concurrency control. When two transactions touch the same row and race to commit, one wins and the other &lt;strong&gt;aborts&lt;/strong&gt; with an OCC error (SQLSTATE &lt;code&gt;40001&lt;/code&gt;/&lt;code&gt;40P01&lt;/code&gt;, or an &lt;code&gt;OC###&lt;/code&gt; code). This is not a failure to paper over — it's the mechanism doing its job. Catch it, back off, retry; on retry the loser re-reads the now-&lt;code&gt;sold&lt;/code&gt; row and correctly rejects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ROLLBACK&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{});&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isOcc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;MAX_RETRY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;isOcc&lt;/code&gt; matches &lt;code&gt;40001&lt;/code&gt;, &lt;code&gt;40P01&lt;/code&gt;, codes starting with &lt;code&gt;OC&lt;/code&gt;, and &lt;code&gt;/serializ|concurrent|conflict/i&lt;/code&gt; in the message. With that loop in place, the &lt;em&gt;naive, unguarded&lt;/em&gt; &lt;code&gt;UPDATE seats SET status='sold'&lt;/code&gt; — no conditional WHERE, no app-level lock — sells one seat exactly once under 60 concurrent cross-region buyers. The database did the hard part.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it bought me
&lt;/h2&gt;

&lt;p&gt;Without DSQL, correctness under a worldwide on-sale would have been &lt;em&gt;my&lt;/em&gt; code's problem: conditional writes, idempotency keys, a distributed lock, reconciliation jobs. With it, the safety property is a property of the database, and my application code got to stay honest and naive — which is exactly what made the side-by-side demo against DynamoDB Global Tables so stark.&lt;/p&gt;

&lt;p&gt;Live: &lt;strong&gt;&lt;a href="https://worldseat.vercel.app" rel="noopener noreferrer"&gt;https://worldseat.vercel.app&lt;/a&gt;&lt;/strong&gt; · the OCC retry count is shown right on the scoreboard.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>database</category>
      <category>serverless</category>
      <category>postgres</category>
    </item>
    <item>
      <title>A Jepsen-lite witness: prove "sold once" from committed history, not app hope</title>
      <dc:creator>Hokutoman00</dc:creator>
      <pubDate>Sun, 21 Jun 2026 17:40:31 +0000</pubDate>
      <link>https://dev.to/hokutoman00/a-jepsen-lite-witness-prove-sold-once-from-committed-history-not-app-hope-53gj</link>
      <guid>https://dev.to/hokutoman00/a-jepsen-lite-witness-prove-sold-once-from-committed-history-not-app-hope-53gj</guid>
      <description>&lt;p&gt;When you claim a system is correct under concurrency, the dangerous move is to ask the &lt;em&gt;application&lt;/em&gt; whether it was correct. The app is the least trustworthy witness in the building: it reports what it &lt;em&gt;intended&lt;/em&gt;, after retries, across a network that drops and reorders. If you count "how many purchase calls returned &lt;code&gt;confirmed&lt;/code&gt;", you are grading the system on its own self-report. That's how demos lie without anyone meaning to lie.&lt;/p&gt;

&lt;p&gt;WorldSeat — a worldwide ticket on-sale built for AWS's Hack the Zero Stack — answers the correctness question with an external checker instead. I call it the &lt;strong&gt;Consistency Witness&lt;/strong&gt;, and it's deliberately Jepsen-shaped: it ignores what the app said and reconstructs the truth from the &lt;em&gt;committed history&lt;/em&gt; in the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  The invariant, reduced to something checkable
&lt;/h2&gt;

&lt;p&gt;Full linearizability checking is expensive. But the safety property a ticketing system actually needs collapses to one tiny invariant:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For one physical seat, there is &lt;strong&gt;at most one&lt;/strong&gt; successful exclusive acquisition.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. If two different buyers each hold a confirmed claim to seat A1, the history is not linearizable — there is no single global order of operations in which both acquisitions of the same exclusive resource succeed. You don't need a full happens-before graph to detect it; you need to count confirmed acquisitions per seat.&lt;/p&gt;

&lt;p&gt;So the witness does exactly that, against committed state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// DSQL: read the committed op_log directly&lt;/span&gt;
&lt;span class="nx"&gt;SELECT&lt;/span&gt; &lt;span class="nx"&gt;seat_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)::&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;AS&lt;/span&gt; &lt;span class="nx"&gt;confirmed&lt;/span&gt;
&lt;span class="nx"&gt;FROM&lt;/span&gt; &lt;span class="nx"&gt;op_log&lt;/span&gt;
&lt;span class="nx"&gt;WHERE&lt;/span&gt; &lt;span class="nx"&gt;outcome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;confirmed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;GROUP&lt;/span&gt; &lt;span class="nx"&gt;BY&lt;/span&gt; &lt;span class="nx"&gt;seat_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// then, for every seat:&lt;/span&gt;
&lt;span class="nx"&gt;doubleSells&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Σ&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;confirmed&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;linearizable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;doubleSells&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;doubleSells&lt;/code&gt; is the number of people who hold a ticket they shouldn't. Zero means every seat was acquired by at most one buyer; anything above zero names the seats with multiple holders.&lt;/p&gt;

&lt;p&gt;For the DynamoDB foil the &lt;em&gt;source&lt;/em&gt; changes but the logic doesn't: the witness reads the append-only sales ledger with &lt;code&gt;ConsistentRead: true&lt;/code&gt; from &lt;strong&gt;both&lt;/strong&gt; regional replicas and unions them, de-duplicated by a globally-unique &lt;code&gt;sale_id&lt;/code&gt;, so cross-region replication lag can't make a double-sell disappear by simply not having arrived yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why read the ledger, not the seats table
&lt;/h2&gt;

&lt;p&gt;This is the subtle part, and it's where eventual consistency hides its damage. On the naive DynamoDB backend, the &lt;code&gt;seats&lt;/code&gt; table eventually converges to a &lt;em&gt;single&lt;/em&gt; owner per seat — last-writer-wins overwrites the others. If you inspected only the seats table, the system would look &lt;em&gt;fine&lt;/em&gt;: one seat, one owner. The oversell is invisible there.&lt;/p&gt;

&lt;p&gt;The truth lives in the &lt;strong&gt;append-only ledger&lt;/strong&gt;, which records every confirmation as it was issued. Three buyers were each told "you got A1" and each got a confirmation code; LWW later picked one to display, but three people are walking to the same chair. The witness reads the ledger precisely because it's the one place the system can't quietly forget what it promised.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconciling two different measurements
&lt;/h2&gt;

&lt;p&gt;WorldSeat shows two numbers that &lt;em&gt;look&lt;/em&gt; like they should match but measure different scopes, and reconciling them honestly was a design point:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Break-it scoreboard&lt;/strong&gt; measures the single seat the last burst targeted.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Witness&lt;/strong&gt; sums double-sells across the &lt;em&gt;whole floor&lt;/em&gt; (every seat with history).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you've run several bursts on different seats, the floor-wide total is legitimately larger than the last seat's count. Rather than paper over that, the witness accepts an optional &lt;code&gt;?seat=&lt;/code&gt; focus so it can report the &lt;em&gt;scope-matched&lt;/em&gt; number for the targeted seat &lt;strong&gt;and&lt;/strong&gt; the floor-wide total side by side — and the UI explicitly prints "✓ reconciled" only when scoreboard oversold equals the witness's focus count for that seat. Matching numbers you didn't engineer to match is the difference between a checker and a prop.&lt;/p&gt;

&lt;h2&gt;
  
  
  The payoff
&lt;/h2&gt;

&lt;p&gt;Because the verdict is computed from committed history every time you ask, it's not a stored boolean you can fake. On Aurora DSQL it reads &lt;strong&gt;Linearizable ✓&lt;/strong&gt; after sixty concurrent buyers hit one seat across two regions. On DynamoDB Global Tables running the &lt;em&gt;same&lt;/em&gt; code it reads &lt;strong&gt;Violated ✗&lt;/strong&gt; and names the over-sold seats. The checker is the same; only the database's consistency model changed the verdict.&lt;/p&gt;

&lt;p&gt;See it live: &lt;strong&gt;&lt;a href="https://worldseat.vercel.app" rel="noopener noreferrer"&gt;https://worldseat.vercel.app&lt;/a&gt;&lt;/strong&gt; — press Break it, then read the Witness.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>database</category>
      <category>distributedsystems</category>
      <category>testing</category>
    </item>
    <item>
      <title>Make database consistency something a judge can break with one click</title>
      <dc:creator>Hokutoman00</dc:creator>
      <pubDate>Sun, 21 Jun 2026 17:40:27 +0000</pubDate>
      <link>https://dev.to/hokutoman00/make-database-consistency-something-a-judge-can-break-with-one-click-1g45</link>
      <guid>https://dev.to/hokutoman00/make-database-consistency-something-a-judge-can-break-with-one-click-1g45</guid>
      <description>&lt;p&gt;Most demos of "strong consistency" ask you to take it on faith. A slide says &lt;em&gt;serializable&lt;/em&gt;, a diagram has some arrows, and you nod. You never see the property do anything, because when consistency works, &lt;em&gt;nothing happens&lt;/em&gt; — that's the whole point. It's invisible plumbing.&lt;/p&gt;

&lt;p&gt;WorldSeat makes the plumbing adversarial. It's a worldwide ticket on-sale where one seat must sell to exactly one fan. There's a button labeled &lt;strong&gt;Break it&lt;/strong&gt;. Press it and the app fires dozens of simultaneous buyers at a single seat, from two AWS regions at once, and counts how many people walked away holding a ticket for the same physical chair.&lt;/p&gt;

&lt;p&gt;The trick that makes this honest: &lt;strong&gt;both backends run the identical naive application code.&lt;/strong&gt; A read-then-write with no application-level locking, no conditional update, no cleverness:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SELECT status FROM seats WHERE seat_id=$1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;seat&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;available&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;rollback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rejected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UPDATE seats SET status=$1, owner=$2 WHERE seat_id=$3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sold&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;buyer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;seat&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the canonical race condition. Two buyers both read &lt;code&gt;available&lt;/code&gt;, both write &lt;code&gt;sold&lt;/code&gt;, both think they won. On any database without serializable isolation, you just sold one seat twice.&lt;/p&gt;

&lt;p&gt;The only variable in WorldSeat is &lt;strong&gt;which AWS database executes that code&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Aurora DSQL&lt;/strong&gt; — distributed SQL, multi-region active-active, &lt;em&gt;serializable&lt;/em&gt; isolation enforced by optimistic concurrency control (OCC). When two transactions conflict, one commits and the other aborts with &lt;code&gt;OC001&lt;/code&gt;/&lt;code&gt;40001&lt;/code&gt;. The app catches it, retries, re-reads &lt;code&gt;sold&lt;/code&gt;, and correctly rejects the second buyer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DynamoDB Global Tables&lt;/strong&gt; — multi-region, &lt;em&gt;eventually consistent&lt;/em&gt;, last-writer-wins. Two buyers in two regions each read &lt;code&gt;available&lt;/code&gt; from their local replica and each write their own &lt;code&gt;sold&lt;/code&gt;. Both succeed. Replication later reconciles to a single owner on the seats table — which quietly &lt;em&gt;hides&lt;/em&gt; the damage — but the append-only sales ledger remembers that two different people were each told "you got it."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the live result from the committed stress test (&lt;code&gt;node scripts/stress.mjs&lt;/code&gt;), hammering seat A1 at escalating concurrency against the production deployment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Aurora DSQL (strong / serializable OCC):
  c= 8  confirmed=1  oversold=0
  c=24  confirmed=1  oversold=0   maxRetries=1
  c=48  confirmed=1  oversold=0   maxRetries=1
  c=60  confirmed=1  oversold=0   maxRetries=1

DynamoDB Global Tables (eventual / LWW):
  c= 8  confirmed= 8  oversold= 7
  c=24  confirmed=12  oversold=11
  c=60  confirmed=33  oversold=32
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same code. Same seat. Same concurrency. The database's consistency model is the entire difference between &lt;em&gt;one&lt;/em&gt; ticket and &lt;em&gt;thirty-three&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A note on &lt;code&gt;maxRetries&lt;/code&gt;, because honesty cuts both ways: it is &lt;em&gt;timing-dependent&lt;/em&gt;, and a perfectly correct run can show &lt;strong&gt;0&lt;/strong&gt;. When a late buyer's transaction begins after the winner has already committed, it simply reads &lt;code&gt;sold&lt;/code&gt; and rejects cleanly — no commit conflict, no retry needed. A non-zero &lt;code&gt;maxRetries&lt;/code&gt; means two commits genuinely interleaved and OCC aborted the loser. &lt;strong&gt;Either path yields oversold = 0&lt;/strong&gt; — that's the claim. The retry counter is supporting evidence that a real race sometimes occurs under the hood, not the headline; the headline is the invariant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why "oversold" is counted from committed state, not hope
&lt;/h2&gt;

&lt;p&gt;It would be easy — and dishonest — to count oversells from what the app &lt;em&gt;thinks&lt;/em&gt; happened (how many requests returned &lt;code&gt;confirmed&lt;/code&gt;). Application return values lie under partition and retry. So WorldSeat never trusts them. The &lt;code&gt;oversold&lt;/code&gt; number is computed by reading the &lt;strong&gt;committed ground truth&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On DSQL, a &lt;code&gt;SELECT count(*) FROM op_log WHERE seat_id=$1 AND outcome='confirmed'&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;On DynamoDB, a strongly-consistent scan of the sales ledger across &lt;em&gt;both&lt;/em&gt; regional replicas, unioned and de-duplicated by a globally-unique &lt;code&gt;sale_id&lt;/code&gt;, so cross-region replication lag can't undercount.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;oversold = confirmed_in_committed_ledger − 1&lt;/code&gt;. One real seat; everything beyond one is a person who will show up to a venue and find someone already sitting there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this teaches that a slide can't
&lt;/h2&gt;

&lt;p&gt;The reason ticketing on-sales melt down — the reason "I had it in my cart and then it was gone" is a universal experience — is precisely this race, at the scale of a stadium and the speed of a fan base refreshing in unison. WorldSeat lets you feel the difference between a database that &lt;em&gt;serializes the stampede for you&lt;/em&gt; and one that makes you, the application developer, responsible for inventing correctness on top of eventual consistency.&lt;/p&gt;

&lt;p&gt;DSQL's value here isn't "it's fast" or "it's managed." It's that it lets you write the &lt;em&gt;naive, obvious&lt;/em&gt; code and still be correct under a worldwide simultaneous on-sale — and you can watch it hold the line, live, at sixty concurrent buyers across two regions, by pressing a button.&lt;/p&gt;

&lt;p&gt;Try it: &lt;strong&gt;&lt;a href="https://worldseat.vercel.app" rel="noopener noreferrer"&gt;https://worldseat.vercel.app&lt;/a&gt;&lt;/strong&gt; — buy a seat, then break it.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>database</category>
      <category>distributedsystems</category>
      <category>hackathon</category>
    </item>
  </channel>
</rss>
