Production engineering
using System;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
int version=1; var receipts=new Dictionary<string,(int Quantity,int Expected,int Result)>();
string Apply(string key,int quantity,int expected) { if(receipts.TryGetValue(key,out var prior))return prior.Quantity==quantity&&prior.Expected==expected&&prior.Result==version?"replay:"+prior.Result:"conflict"; if(expected!=version)return "stale"; version++; receipts.Add(key,(quantity,expected,version)); return "committed:"+version; }
Console.WriteLine(Apply("demo",2,1)); Console.WriteLine(Apply("demo",2,1)); Console.WriteLine(Apply("demo",3,1)); Console.WriteLine(Apply("second",2,1));
Reveal answer and reasoning
The output lines, in order, are “committed:2”; “replay:2”; “conflict”; “stale”. The portable .NET9 console companion begins at version one with an empty dictionary of receipts. Applying demo with quantity two and expected version one increments the version and records result two, printing committed:2. The identical call finds matching quantity, expected version and current result, so it prints replay:2 without another increment.
Changing demo's quantity produces conflict. A new second key carrying the old expected version prints stale. These are actual one-owner dictionary and integer decisions, not parsed HTTP conditions, database atomicity or delivered messages. They explain the narrow receipt policy that the external transaction then implements with real framework and SQL operations.
Request equivalence is explicit and narrower than an unrestricted semantic comparison: quantity and the serialized original typed condition are bound together. Reusing a key with changed meaning conflicts. Later unrelated writes can also make an otherwise matching saved receipt noncurrent, producing409 under this chosen protocol. A new stale condition produces412 instead. SQLite's immediate write ownership makes this local decision boundary inspectable, but no general cross-database transaction guarantee follows.
The outbox row records intent only; publication, consumer replay handling, ordering and effects outside this database need separate owners. A successful receipt does not demonstrate that any broker or remote consumer ran.
What a strong answer covers
- Exact output: committed:2 | replay:2 | conflict | stale
- The portable .NET9 console companion begins at version one with an empty dictionary of receipts.
- Request equivalence is explicit and narrower than an unrestricted semantic comparison: quantity and the serialized original typed condition are bound together.
Common pitfall
Request equivalence is explicit and narrower than an unrestricted semantic comparison: quantity and the serialized original typed condition are bound together. Reusing a key with changed meaning conflicts. Later unrelated writes can also make an otherwise matching saved receipt noncurrent, producing409 under this chosen protocol. A new stale condition produces412 instead. SQLite's immediate write ownership makes this local decision boundary inspectable, but no general cross-database transaction guarantee follows. The outbox row records intent only; publication, consumer replay handling, ordering and effects outside this database need separate owners. A successful receipt does not demonstrate that any broker or remote consumer ran.
Follow-up questions
- Why does replacing the original If-Match value with the result ETag change the saved request identity during a replay?
- Why does an outbox row prove persisted intent rather than broker publication or a consumer effect?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.