Middle · Trace · Transactional inbox and full request equivalence

Portable .NET9 console only: predict every printed line and explain why the same id can produce created, replay and conflict while the effect remains3. State which real HTTP, SQL or infrastructure guarantee this program does not test.

Think through your answer before opening the explanation.

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;

var seen=new Dictionary<string,(string Payload,int Amount)>(); int effects=0;
string Apply(string id,string payload,int amount) { var value=(payload,amount); if(seen.TryGetValue(id,out var prior))return prior==value?"replay":"conflict"; seen.Add(id,value); effects+=amount; return "created"; }
Console.WriteLine(Apply("demo","rune",3)); Console.WriteLine(Apply("demo","rune",3)); Console.WriteLine(Apply("demo","rune",4)); Console.WriteLine("effects:"+effects);
Reveal answer and reasoning

The console applies demo with payload rune and amount three, records that tuple and prints created. Repeating the exact tuple prints replay without adding the amount again. Reusing demo with amount four prints conflict, because the tuple differs even though the payload text is unchanged. The final line is effects:3. Tuple equality over these strings and integers is ordinary C# behavior, not a transaction or cross-process lock.

The helper also does not define a cryptographic canonical JSON standard; it compares the supplied meaningful values directly under its one dictionary owner.

The external controlled-failure request inserts inbox identity and changes the local effect before rolling back, leaving both inbox and effects at zero. A valid request then stores one canonical DTO representation and raises the effect to three. Its exact replay returns replay true without another update, while changing only amount produces409. Fresh counts remain inbox one and effects three. These independent inputs prove that the external comparison includes amount rather than accidentally deduplicating only the label.

They also distinguish rollback from replay; an operation that never committed must not be hidden as an already applied success.

What a strong answer covers

  • The known tuple includes payload and amount; changed amount is not a compatible replay.
  • The console effect remains3 after exact replay and conflict.
  • The actual inbox and local SQL effect commit or roll back together; remote effects remain separate.

Common pitfall

Deduplicating only a label or claiming that an inbox transaction also covers an unrelated remote side effect.

Follow-up questions

  1. How should identity be namespaced across producers or tenants?
  2. What evidence distinguishes rollback before commit from replay after commit?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions