Exercise 17 · All failures at once and all defences
The whole system under pressure
- souhrn
- chaos
- Outbox + Inbox + Saga
Principle
Finally, all failures combine: lost publication, service errors, duplicates, shuffled order, lost acknowledgements.
The defences complement each other: Outbox guarantees publication, retry+DLQ handles transient errors, Inbox/idempotency handles duplicates, corrSeq handles order and Saga compensates the irreversible.
None of them is enough on its own. Turn them on one at a time and watch which cause each one removes.
What to watch
- The “Cause → Effect” diagnosis on the right.
- Which switch removes which unwanted effects.
Experiment
What to do: Click “Run chaos without defences”. What to look at: The process does not complete consistently: duplicates, a double payout or a hanging process appear.
Services fail, messages are duplicated and lost. No defence is enabled.
The same conditions, but with defences enabled. The process completes consistently, just more slowly.
Step by step (newest on top)
Event Store: append-only history (newest on top)
Message Broker: delivery (newest on top)
Projection (current state)
The simulation needs JavaScript. Below is a recording of both runs.
Run chaos without defences
Services fail, messages are duplicated and lost. No defence is enabled.
0.0 sMortgage Calculator APIcould not publish to the broker
MortgageApplicationSubmittedintegrationpublishing to the broker failed
The event is stored, but nobody will learn about it: the process is stuck (dual write problem)
0.0 sMortgage Calculator APIappended to the event store
MortgageApplicationSubmittedintegrationEvent content
{ "applicationId": "calc-1", "referenceNumber": "KALK-calc-1-2", "loanAmount": 5200000, "monthlyPayment": 29590, "monthlyIncome": 85000, "termYears": 30, "ratePct": 5.49, "dti": 0.34811764705882353, "ltv": 0.8 }0.0 sMortgage Calculator APIappended to the event store
ApplicationSubmitteddomainEvent content
{ "calculationId": "calc-1", "referenceNumber": "KALK-calc-1-2", "inputs": { "monthlyIncome": 85000, "propertyPrice": 6500000, "downPaymentPct": 20, "ratePct": 5.49, "termYears": 30 }, "result": { "loan": 5200000, "monthlyPayment": 29590, "dti": 0.34811764705882353, "ltv": 0.8, "algorithm": "v1" } }0.0 sMortgage Calculator APIappended to the event store
CalculationCompleteddomainEvent content
{ "algorithm": "v1", "result": { "loan": 5200000, "monthlyPayment": 29590, "dti": 0.34811764705882353, "ltv": 0.8, "algorithm": "v1" }, "referenceNumber": "KALK-calc-1-2" }0.0 sMortgage Calculator APIappended to the event store
CalculationCreateddomainEvent content
{ "calculationId": "calc-1", "monthlyIncome": 85000, "propertyPrice": 6500000, "downPaymentPct": 20, "ratePct": 5.49, "termYears": 30 }
Run chaos with all defences
The same conditions, but with defences enabled. The process completes consistently, just more slowly.
19.13 sProjection (read model)processed
MortgageDisbursementRequestedcommand18.9 sProjection (read model)picked up
MortgageDisbursementRequestedcommandattempt 1
18.88 sProjection (read model)processed
MortgageDisbursedintegration18.88 sProjection (read model)buffered
MortgageDisbursedintegrationwaiting for corrSeq 11
18.58 sProjection (read model)picked up
MortgageDisbursedintegrationattempt 1
16.98 sProjection (read model)processed
ContractSignedintegration16.7 sProjection (read model)picked up
ContractSignedintegrationattempt 1
16.25 sProcess Manager (Saga)processed
MortgageDisbursedintegration15.93 sProcess Manager (Saga)picked up
MortgageDisbursedintegrationattempt 1
15.8 sDisbursementignored a duplicate (Inbox)
MortgageDisbursementRequestedcommandInbox: eventId already processed
15.5 sDisbursementsent from the Outbox
MortgageDisbursedintegrationsent on attempt 1
15.33 sProjection (read model)processed
ContractGenerationRequestedcommand15.2 sDisbursementpicked up
MortgageDisbursementRequestedcommandattempt 1
15.2 sDisbursementprocessed
MortgageDisbursementRequestedcommand15.2 sDisbursementstored in the Outbox
MortgageDisbursedintegrationfor: Process Manager (Saga)Projection (read model)
Event content
{ "amount": 5200000, "accountNumber": "0800-100017/0800" }14.98 sProjection (read model)picked up
ContractGenerationRequestedcommandattempt 1
14.98 sProjection (read model)processed
MortgageAccountOpenedintegration14.6 sProjection (read model)picked up
MortgageAccountOpenedintegrationattempt 1
14.55 sDisbursementpicked up
MortgageDisbursementRequestedcommandattempt 1
14.18 sProcess Manager (Saga)sent from the Outbox
MortgageDisbursementRequestedcommandsent on attempt 1
14.18 sDisbursementreceives the message twice
MortgageDisbursementRequestedcommandbroker delivers the message 2×
13.88 sProcess Manager (Saga)processed
ContractSignedintegration13.88 sProcess Manager (Saga)stored in the Outbox
MortgageDisbursementRequestedcommandfor: DisbursementProjection (read model)
Event content
{ "applicationId": "calc-1", "amount": 5200000, "accountNumber": "0800-100017/0800", "customerId": "CUST-0001" }13.63 sProcess Manager (Saga)picked up
ContractSignedintegrationattempt 1
13.18 sDocument Servicesent from the Outbox
ContractSignedintegrationsent on attempt 1
12.88 sDocument Servicestored in the Outbox
ContractSignedintegrationfor: Process Manager (Saga)Projection (read model)
Event content
{ "contractId": "SML-0001", "signedBy": "klient" }12.88 sProjection (read model)ignored a duplicate (Inbox)
CustomerIdentityCreatedintegrationInbox: eventId already processed
12.5 sProjection (read model)picked up
CustomerIdentityCreatedintegrationattempt 1
12.38 sProjection (read model)processed
ContractGeneratedintegration12.38 sProjection (read model)buffered
ContractGeneratedintegrationwaiting for corrSeq 7
12.3 sProcess Manager (Saga)processed
ContractGeneratedintegration12.05 sProjection (read model)picked up
ContractGeneratedintegrationattempt 1
12.03 sProjection (read model)processed
MortgageAccountOpeningRequestedcommand11.98 sProcess Manager (Saga)picked up
ContractGeneratedintegrationattempt 1
11.68 sProjection (read model)picked up
MortgageAccountOpeningRequestedcommandattempt 1
11.65 sDocument Servicesent from the Outbox
ContractGeneratedintegrationsent on attempt 1
11.35 sDocument Serviceprocessed
ContractGenerationRequestedcommand11.35 sDocument Servicestored in the Outbox
ContractGeneratedintegrationfor: Process Manager (Saga)Projection (read model)
Event content
{ "contractId": "SML-0001" }10.7 sDocument Servicepicked up
ContractGenerationRequestedcommandattempt 1
10.3 sProcess Manager (Saga)sent from the Outbox
ContractGenerationRequestedcommandsent on attempt 1
10.15 sProjection (read model)processed
CustomerIdentityCreationRequestedcommand10.0 sProcess Manager (Saga)processed
MortgageAccountOpenedintegration10.0 sProcess Manager (Saga)stored in the Outbox
ContractGenerationRequestedcommandfor: Document ServiceProjection (read model)
Event content
{ "applicationId": "calc-1", "amount": 5200000, "accountNumber": "0800-100017/0800", "customerId": "CUST-0001" }9.83 sProjection (read model)picked up
CustomerIdentityCreationRequestedcommandattempt 1
9.75 sProcess Manager (Saga)picked up
MortgageAccountOpenedintegrationattempt 1
9.45 sProjection (read model)processed
CustomerIdentityCreatedintegration9.45 sProjection (read model)buffered
CustomerIdentityCreatedintegrationwaiting for corrSeq 4
9.33 sMortgage Accountsent from the Outbox
MortgageAccountOpenedintegrationsent on attempt 1
9.08 sProjection (read model)picked up
CustomerIdentityCreatedintegrationattempt 1
9.03 sMortgage Accountprocessed
MortgageAccountOpeningRequestedcommand9.03 sMortgage Accountstored in the Outbox
MortgageAccountOpenedintegrationfor: Process Manager (Saga)Projection (read model)
Event content
{ "accountNumber": "0800-100017/0800" }8.48 sProjection (read model)ignored a duplicate (Inbox)
RiskAssessmentCompletedintegrationInbox: eventId already processed
8.4 sMortgage Accountpicked up
MortgageAccountOpeningRequestedcommandattempt 1
8.23 sProjection (read model)picked up
RiskAssessmentCompletedintegrationattempt 1
7.98 sProcess Manager (Saga)sent from the Outbox
MortgageAccountOpeningRequestedcommandsent on attempt 1
7.68 sProcess Manager (Saga)processed
CustomerIdentityCreatedintegration7.68 sProcess Manager (Saga)stored in the Outbox
MortgageAccountOpeningRequestedcommandfor: Mortgage AccountProjection (read model)
Event content
{ "applicationId": "calc-1", "amount": 5200000, "customerId": "CUST-0001" }7.6 sProjection (read model)processed
MortgageApprovedintegration7.35 sProcess Manager (Saga)picked up
CustomerIdentityCreatedintegrationattempt 1
7.33 sProjection (read model)picked up
MortgageApprovedintegrationattempt 1
6.95 sCustomer Identitysent from the Outbox
CustomerIdentityCreatedintegrationsent on attempt 1
6.95 sProjection (read model)receives the message twice
CustomerIdentityCreatedintegrationbroker delivers the message 2×
6.65 sCustomer Identityprocessed
CustomerIdentityCreationRequestedcommand6.65 sCustomer Identitystored in the Outbox
CustomerIdentityCreatedintegrationfor: Process Manager (Saga)Projection (read model)
Event content
{ "customerId": "CUST-0001" }6.05 sCustomer Identitypicked up
CustomerIdentityCreationRequestedcommandattempt 1
5.7 sProcess Manager (Saga)sent from the Outbox
CustomerIdentityCreationRequestedcommandsent on attempt 2
5.23 sProjection (read model)processed
RiskAssessmentCompletedintegration5.2 sProcess Manager (Saga)failed while processing
CustomerIdentityCreationRequestedcommandrelay: broker unavailable, attempt 1
4.9 sProcess Manager (Saga)processed
MortgageApprovedintegration4.9 sProcess Manager (Saga)stored in the Outbox
CustomerIdentityCreationRequestedcommandfor: Customer IdentityProjection (read model)
Event content
{ "applicationId": "calc-1", "amount": 5200000 }4.85 sProjection (read model)picked up
RiskAssessmentCompletedintegrationattempt 1
4.73 sProjection (read model)processed
MortgageApplicationSubmittedintegration4.53 sProcess Manager (Saga)picked up
MortgageApprovedintegrationattempt 1
4.38 sProjection (read model)picked up
MortgageApplicationSubmittedintegrationattempt 1
4.13 sApproval / Controllingsent from the Outbox
MortgageApprovedintegrationsent on attempt 1
3.83 sApproval / Controllingprocessed
RiskAssessmentCompletedintegration3.83 sApproval / Controllingstored in the Outbox
MortgageApprovedintegrationfor: Process Manager (Saga)Projection (read model)
Event content
{ "approvedAmount": 5200000, "score": 800 }3.33 sApproval / Controllingpicked up
RiskAssessmentCompletedintegrationattempt 1
3.0 sRisk Servicesent from the Outbox
RiskAssessmentCompletedintegrationsent on attempt 2
3.0 sProjection (read model)receives the message twice
RiskAssessmentCompletedintegrationbroker delivers the message 2×
2.5 sRisk Servicefailed while processing
RiskAssessmentCompletedintegrationrelay: broker unavailable, attempt 1
2.2 sRisk Serviceprocessed
MortgageApplicationSubmittedintegration2.2 sRisk Servicestored in the Outbox
RiskAssessmentCompletedintegrationfor: Approval / ControllingProjection (read model)
Event content
{ "score": 800, "loanAmount": 5200000, "monthlyIncome": 85000, "dti": 0.34811764705882353, "ltv": 0.8 }1.93 sProcess Manager (Saga)processed
MortgageApplicationSubmittedintegration1.7 sRisk Servicepicked up
MortgageApplicationSubmittedintegrationattempt 1
1.65 sProcess Manager (Saga)picked up
MortgageApplicationSubmittedintegrationattempt 1
1.3 sMortgage Calculator APIsent from the Outbox
MortgageApplicationSubmittedintegrationsent on attempt 3
0.8 sMortgage Calculator APIfailed while processing
MortgageApplicationSubmittedintegrationrelay: broker unavailable, attempt 2
0.3 sMortgage Calculator APIfailed while processing
MortgageApplicationSubmittedintegrationrelay: broker unavailable, attempt 1
0.0 sMortgage Calculator APIstored in the Outbox
MortgageApplicationSubmittedintegrationfor: Risk ServiceProcess Manager (Saga)Projection (read model)
Event content
{ "applicationId": "calc-1", "referenceNumber": "KALK-calc-1-2", "loanAmount": 5200000, "monthlyPayment": 29590, "monthlyIncome": 85000, "termYears": 30, "ratePct": 5.49, "dti": 0.34811764705882353, "ltv": 0.8 }0.0 sMortgage Calculator APIappended to the event store
ApplicationSubmitteddomainEvent content
{ "calculationId": "calc-1", "referenceNumber": "KALK-calc-1-2", "inputs": { "monthlyIncome": 85000, "propertyPrice": 6500000, "downPaymentPct": 20, "ratePct": 5.49, "termYears": 30 }, "result": { "loan": 5200000, "monthlyPayment": 29590, "dti": 0.34811764705882353, "ltv": 0.8, "algorithm": "v1" } }0.0 sMortgage Calculator APIappended to the event store
CalculationCompleteddomainEvent content
{ "algorithm": "v1", "result": { "loan": 5200000, "monthlyPayment": 29590, "dti": 0.34811764705882353, "ltv": 0.8, "algorithm": "v1" }, "referenceNumber": "KALK-calc-1-2" }0.0 sMortgage Calculator APIappended to the event store
CalculationCreateddomainEvent content
{ "calculationId": "calc-1", "monthlyIncome": 85000, "propertyPrice": 6500000, "downPaymentPct": 20, "ratePct": 5.49, "termYears": 30 }
What happens in the simulator
A summary of the same scenario you run in the lab. The individual steps are shown with the runs above.
4 events · 0.3 s of simulated time
Cause → effect
- Publishing MortgageApplicationSubmitted to the broker failed after writing to the event store → The event is stored, but nobody will learn about it: the process is stuck (dual write problem) MortgageApplicationSubmitted
15 events · 19.2 s of simulated time
Try it in your own project
Copy the prompt into your coding agent (Claude Code, Copilot, Codex…) and run it in your project's repository.
Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing.
# Task for a coding agent: The whole system under pressure Stack: Java. Mode: guided. Goal: Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing. ## Context of the existing code You are working in an existing project (Java backend (typically Java 21, Spring Boot, JPA or JDBC). Use the build tool and style the project already has (Maven/Gradle, JUnit 5).). Domain: a mortgage calculator that is gradually turning into an event-driven system (calculator, risk, approval, identity, account, documents, payout). Prerequisite: the project has asynchronous onboarding via a broker all the way to payout; the harness will show the missing defences. If the flow is missing, first create a minimal in-memory flow. Read first, change nothing. Find and briefly summarise: - Existing onboarding integration/e2e tests. - Fault-injection options: what takes time, timers, randomness and the network when the system is composed; inject faults and virtual time there as optional parameters (default behaviour unchanged). - Metrics: queues, DLQ, message age. - Which of these parts already exist in the project and which are missing. Before writing your own test infrastructure (virtual time, PRNG, fake broker), check whether the project or organisation already has it as a ready-made library, and use it. If it is missing, propose it in the plan. ## Expected behaviour With all faults at once, the defences complement each other (Outbox, retry and DLQ, Inbox and idempotency, correlation sequence, Saga) and none is enough on its own; with all of them the process completes consistently, just more slowly. Example: the “duplicate” profile (the document service writes the contract, the response is lost) finds two contracts for one application. ## Specific task Technical specifics (Java): JUnit + Toxiproxy/Testcontainers or a fake broker with injected faults. Proceed step by step. After point 1 (plan), write what you found and what you propose, and wait for confirmation: 1. Plan: a table of failure × defence × invariant. Loss: a consumer stops consuming for a while. Duplicate: delivery 2×, lost publish acknowledgement, lost response after a write. Order: a message reaches a consumer after the next one. Offline: a service, the broker or the browser. Slow service: response after the client timeout, the write goes through. 2. A test harness with injected faults and a fixed seed: profile = one kind of failure, a separate PRNG for each kind of fault and for jitter, and after the run a snapshot of the world (service tables, broker log, read models, process state). 3. Post-run invariants as pure functions of the snapshot (source of truth = service tables and the broker log): a completed application has exactly one account, one contract and one payout; a rejected or reverted one has nothing open; read models = source of truth; nothing is left hanging. Also measure side effects (extra calls, retries, DLQ). 4. Run the harness for each profile with seeds 1–10 and print a table: profile × invariant, first violating seed, missing defence. 5. Fix one gap: the most frequent violation with business impact that can be fixed without changing other people's tests. Put the rest in the backlog. Watch out for: - A test that fails once in a hundred runs is worse than none: a fixed seed and multiple seeds. - Use a temporary mutation of a defence to verify that the harness really finds the violation. - Someone else's test that is sensitive to real time may fail even on the baseline: do not change it, and mention it in the conclusion. ## What you must not change - The existing public API and the behaviour of the calculator endpoints that currently work. - The database schema of existing tables (new tables/migrations are fine; renaming and deleting are not). - Other people's tests, seed data and existing values. If a change is necessary, put it in a separate commit and state it. If a change to an event's shape or a new consumer necessarily changes an existing test, update it in a separate commit and explain why in the summary. - Public contracts (APIs, event schemas) without backward compatibility. ## Done when - The test is reproducible: two runs with the same seed give the same fingerprint; the seed is in the test name. - Invariants are explicit (in code and in the README). - Open risks are in the README, each with a test; the fixed gap has a test that failed before the fix. - JUnit 5 tests in the existing `src/test/java` structure pass with the project's build tool. - In the summary, state: what you changed, what you assumed, what remains.
# Task for a coding agent: The whole system under pressure Stack: Java. Mode: challenge. Goal: Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing. ## Context of the existing code You are working in an existing project (Java backend (typically Java 21, Spring Boot, JPA or JDBC). Use the build tool and style the project already has (Maven/Gradle, JUnit 5).). Domain: a mortgage calculator that is gradually turning into an event-driven system (calculator, risk, approval, identity, account, documents, payout). Prerequisite: the project has asynchronous onboarding via a broker all the way to payout; the harness will show the missing defences. If the flow is missing, first create a minimal in-memory flow. Read first, change nothing. Find and briefly summarise: - Existing onboarding integration/e2e tests. - Fault-injection options: what takes time, timers, randomness and the network when the system is composed; inject faults and virtual time there as optional parameters (default behaviour unchanged). - Metrics: queues, DLQ, message age. - Which of these parts already exist in the project and which are missing. Before writing your own test infrastructure (virtual time, PRNG, fake broker), check whether the project or organisation already has it as a ready-made library, and use it. If it is missing, propose it in the plan. ## Expected behaviour With all faults at once, the defences complement each other (Outbox, retry and DLQ, Inbox and idempotency, correlation sequence, Saga) and none is enough on its own; with all of them the process completes consistently, just more slowly. Example: the “duplicate” profile (the document service writes the contract, the response is lost) finds two contracts for one application. ## Brief (Challenge) Write a reproducible chaos test of onboarding with post-run invariants and show which failures are not yet handled. Technical specifics (Java): JUnit + Toxiproxy/Testcontainers or a fake broker with injected faults. Choose your own approach. The pitfalls in this topic are not listed: find them (concurrency, redelivery, ordering, failure midway) and for each write a test that would expose it. At the end, list which pitfalls you found and which you deliberately left open. ## What you must not change - The existing public API and the behaviour of the calculator endpoints that currently work. - The database schema of existing tables (new tables/migrations are fine; renaming and deleting are not). - Other people's tests, seed data and existing values. If a change is necessary, put it in a separate commit and state it. If a change to an event's shape or a new consumer necessarily changes an existing test, update it in a separate commit and explain why in the summary. - Public contracts (APIs, event schemas) without backward compatibility. ## Done when - The test is reproducible: two runs with the same seed give the same fingerprint; the seed is in the test name. - Invariants are explicit (in code and in the README). - Open risks are in the README, each with a test; the fixed gap has a test that failed before the fix. - JUnit 5 tests in the existing `src/test/java` structure pass with the project's build tool. - In the summary, state: what you changed, what you assumed, what remains.
# Task for a coding agent: The whole system under pressure Stack: C#. Mode: guided. Goal: Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing. ## Context of the existing code You are working in an existing project (C# backend (.NET, ASP.NET Core, EF Core or Dapper). Use the solution, style and DI conventions the project already has (xUnit/NUnit).). Domain: a mortgage calculator that is gradually turning into an event-driven system (calculator, risk, approval, identity, account, documents, payout). Prerequisite: the project has asynchronous onboarding via a broker all the way to payout; the harness will show the missing defences. If the flow is missing, first create a minimal in-memory flow. Read first, change nothing. Find and briefly summarise: - Existing onboarding integration/e2e tests. - Fault-injection options: what takes time, timers, randomness and the network when the system is composed; inject faults and virtual time there as optional parameters (default behaviour unchanged). - Metrics: queues, DLQ, message age. - Which of these parts already exist in the project and which are missing. Before writing your own test infrastructure (virtual time, PRNG, fake broker), check whether the project or organisation already has it as a ready-made library, and use it. If it is missing, propose it in the plan. ## Expected behaviour With all faults at once, the defences complement each other (Outbox, retry and DLQ, Inbox and idempotency, correlation sequence, Saga) and none is enough on its own; with all of them the process completes consistently, just more slowly. Example: the “duplicate” profile (the document service writes the contract, the response is lost) finds two contracts for one application. ## Specific task Technical specifics (C#): xUnit + a broker test harness (e.g. MassTransit test harness) with injected faults. Proceed step by step. After point 1 (plan), write what you found and what you propose, and wait for confirmation: 1. Plan: a table of failure × defence × invariant. Loss: a consumer stops consuming for a while. Duplicate: delivery 2×, lost publish acknowledgement, lost response after a write. Order: a message reaches a consumer after the next one. Offline: a service, the broker or the browser. Slow service: response after the client timeout, the write goes through. 2. A test harness with injected faults and a fixed seed: profile = one kind of failure, a separate PRNG for each kind of fault and for jitter, and after the run a snapshot of the world (service tables, broker log, read models, process state). 3. Post-run invariants as pure functions of the snapshot (source of truth = service tables and the broker log): a completed application has exactly one account, one contract and one payout; a rejected or reverted one has nothing open; read models = source of truth; nothing is left hanging. Also measure side effects (extra calls, retries, DLQ). 4. Run the harness for each profile with seeds 1–10 and print a table: profile × invariant, first violating seed, missing defence. 5. Fix one gap: the most frequent violation with business impact that can be fixed without changing other people's tests. Put the rest in the backlog. Watch out for: - A test that fails once in a hundred runs is worse than none: a fixed seed and multiple seeds. - Use a temporary mutation of a defence to verify that the harness really finds the violation. - Someone else's test that is sensitive to real time may fail even on the baseline: do not change it, and mention it in the conclusion. ## What you must not change - The existing public API and the behaviour of the calculator endpoints that currently work. - The database schema of existing tables (new tables/migrations are fine; renaming and deleting are not). - Other people's tests, seed data and existing values. If a change is necessary, put it in a separate commit and state it. If a change to an event's shape or a new consumer necessarily changes an existing test, update it in a separate commit and explain why in the summary. - Public contracts (APIs, event schemas) without backward compatibility. ## Done when - The test is reproducible: two runs with the same seed give the same fingerprint; the seed is in the test name. - Invariants are explicit (in code and in the README). - Open risks are in the README, each with a test; the fixed gap has a test that failed before the fix. - Tests in the existing test project pass (`dotnet test`). - In the summary, state: what you changed, what you assumed, what remains.
# Task for a coding agent: The whole system under pressure Stack: C#. Mode: challenge. Goal: Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing. ## Context of the existing code You are working in an existing project (C# backend (.NET, ASP.NET Core, EF Core or Dapper). Use the solution, style and DI conventions the project already has (xUnit/NUnit).). Domain: a mortgage calculator that is gradually turning into an event-driven system (calculator, risk, approval, identity, account, documents, payout). Prerequisite: the project has asynchronous onboarding via a broker all the way to payout; the harness will show the missing defences. If the flow is missing, first create a minimal in-memory flow. Read first, change nothing. Find and briefly summarise: - Existing onboarding integration/e2e tests. - Fault-injection options: what takes time, timers, randomness and the network when the system is composed; inject faults and virtual time there as optional parameters (default behaviour unchanged). - Metrics: queues, DLQ, message age. - Which of these parts already exist in the project and which are missing. Before writing your own test infrastructure (virtual time, PRNG, fake broker), check whether the project or organisation already has it as a ready-made library, and use it. If it is missing, propose it in the plan. ## Expected behaviour With all faults at once, the defences complement each other (Outbox, retry and DLQ, Inbox and idempotency, correlation sequence, Saga) and none is enough on its own; with all of them the process completes consistently, just more slowly. Example: the “duplicate” profile (the document service writes the contract, the response is lost) finds two contracts for one application. ## Brief (Challenge) Write a reproducible chaos test of onboarding with post-run invariants and show which failures are not yet handled. Technical specifics (C#): xUnit + a broker test harness (e.g. MassTransit test harness) with injected faults. Choose your own approach. The pitfalls in this topic are not listed: find them (concurrency, redelivery, ordering, failure midway) and for each write a test that would expose it. At the end, list which pitfalls you found and which you deliberately left open. ## What you must not change - The existing public API and the behaviour of the calculator endpoints that currently work. - The database schema of existing tables (new tables/migrations are fine; renaming and deleting are not). - Other people's tests, seed data and existing values. If a change is necessary, put it in a separate commit and state it. If a change to an event's shape or a new consumer necessarily changes an existing test, update it in a separate commit and explain why in the summary. - Public contracts (APIs, event schemas) without backward compatibility. ## Done when - The test is reproducible: two runs with the same seed give the same fingerprint; the seed is in the test name. - Invariants are explicit (in code and in the README). - Open risks are in the README, each with a test; the fixed gap has a test that failed before the fix. - Tests in the existing test project pass (`dotnet test`). - In the summary, state: what you changed, what you assumed, what remains.
# Task for a coding agent: The whole system under pressure Stack: Web (HTML/JS or the app's stack). Mode: guided. Goal: Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing. ## Context of the existing code You are working in an existing project (web application: a browser frontend, possibly with its own backend. If the project has a backend, the event store, broker and services belong on the backend, and the points about endpoints and tables refer to it. If it has no backend, use IndexedDB in the browser and `fake-indexeddb` in tests. Keep the project's framework and test runner; add new dependencies only with a justification.). Domain: a mortgage calculator that is gradually turning into an event-driven system (calculator, risk, approval, identity, account, documents, payout). Prerequisite: the project has asynchronous onboarding via a broker all the way to payout; the harness will show the missing defences. If the flow is missing, first create a minimal in-memory flow. Read first, change nothing. Find and briefly summarise: - Existing onboarding integration/e2e tests. - Fault-injection options: what takes time, timers, randomness and the network when the system is composed; inject faults and virtual time there as optional parameters (default behaviour unchanged). - Metrics: queues, DLQ, message age. - Which of these parts already exist in the project and which are missing. Before writing your own test infrastructure (virtual time, PRNG, fake broker), check whether the project or organisation already has it as a ready-made library, and use it. If it is missing, propose it in the plan. ## Expected behaviour With all faults at once, the defences complement each other (Outbox, retry and DLQ, Inbox and idempotency, correlation sequence, Saga) and none is enough on its own; with all of them the process completes consistently, just more slowly. Example: the “duplicate” profile (the document service writes the contract, the response is lost) finds two contracts for one application. ## Specific task Technical specifics (Web (HTML/JS or the app's stack)): Vitest with a deterministic PRNG (seed) and fake time: only the harness advances the clock and timers. The whole run is in a single process without a network (API, service HTTP handlers, in-memory broker); fake timers over real HTTP are not reproducible. Proceed step by step. After point 1 (plan), write what you found and what you propose, and wait for confirmation: 1. Plan: a table of failure × defence × invariant. Loss: a consumer stops consuming for a while. Duplicate: delivery 2×, lost publish acknowledgement, lost response after a write. Order: a message reaches a consumer after the next one. Offline: a service, the broker or the browser. Slow service: response after the client timeout, the write goes through. 2. A test harness with injected faults and a fixed seed: profile = one kind of failure, a separate PRNG for each kind of fault and for jitter, and after the run a snapshot of the world (service tables, broker log, read models, process state). 3. Post-run invariants as pure functions of the snapshot (source of truth = service tables and the broker log): a completed application has exactly one account, one contract and one payout; a rejected or reverted one has nothing open; read models = source of truth; nothing is left hanging. Also measure side effects (extra calls, retries, DLQ). 4. Run the harness for each profile with seeds 1–10 and print a table: profile × invariant, first violating seed, missing defence. 5. Fix one gap: the most frequent violation with business impact that can be fixed without changing other people's tests. Put the rest in the backlog. Watch out for: - A test that fails once in a hundred runs is worse than none: a fixed seed and multiple seeds. - Use a temporary mutation of a defence to verify that the harness really finds the violation. - Someone else's test that is sensitive to real time may fail even on the baseline: do not change it, and mention it in the conclusion. ## What you must not change - The existing public API and the behaviour of the calculator endpoints that currently work. - The database schema of existing tables (new tables/migrations are fine; renaming and deleting are not). - Other people's tests, seed data and existing values. If a change is necessary, put it in a separate commit and state it. If a change to an event's shape or a new consumer necessarily changes an existing test, update it in a separate commit and explain why in the summary. - Public contracts (APIs, event schemas) without backward compatibility. ## Done when - The test is reproducible: two runs with the same seed give the same fingerprint; the seed is in the test name. - Invariants are explicit (in code and in the README). - Open risks are in the README, each with a test; the fixed gap has a test that failed before the fix. - Tests pass with the existing test runner; lint and build pass if the project has them. - In the summary, state: what you changed, what you assumed, what remains.
# Task for a coding agent: The whole system under pressure Stack: Web (HTML/JS or the app's stack). Mode: challenge. Goal: Build a resilience test (chaos test) of the whole onboarding and use it to determine which defences are still missing. ## Context of the existing code You are working in an existing project (web application: a browser frontend, possibly with its own backend. If the project has a backend, the event store, broker and services belong on the backend, and the points about endpoints and tables refer to it. If it has no backend, use IndexedDB in the browser and `fake-indexeddb` in tests. Keep the project's framework and test runner; add new dependencies only with a justification.). Domain: a mortgage calculator that is gradually turning into an event-driven system (calculator, risk, approval, identity, account, documents, payout). Prerequisite: the project has asynchronous onboarding via a broker all the way to payout; the harness will show the missing defences. If the flow is missing, first create a minimal in-memory flow. Read first, change nothing. Find and briefly summarise: - Existing onboarding integration/e2e tests. - Fault-injection options: what takes time, timers, randomness and the network when the system is composed; inject faults and virtual time there as optional parameters (default behaviour unchanged). - Metrics: queues, DLQ, message age. - Which of these parts already exist in the project and which are missing. Before writing your own test infrastructure (virtual time, PRNG, fake broker), check whether the project or organisation already has it as a ready-made library, and use it. If it is missing, propose it in the plan. ## Expected behaviour With all faults at once, the defences complement each other (Outbox, retry and DLQ, Inbox and idempotency, correlation sequence, Saga) and none is enough on its own; with all of them the process completes consistently, just more slowly. Example: the “duplicate” profile (the document service writes the contract, the response is lost) finds two contracts for one application. ## Brief (Challenge) Write a reproducible chaos test of onboarding with post-run invariants and show which failures are not yet handled. Technical specifics (Web (HTML/JS or the app's stack)): Vitest with a deterministic PRNG (seed) and fake time: only the harness advances the clock and timers. The whole run is in a single process without a network (API, service HTTP handlers, in-memory broker); fake timers over real HTTP are not reproducible. Choose your own approach. The pitfalls in this topic are not listed: find them (concurrency, redelivery, ordering, failure midway) and for each write a test that would expose it. At the end, list which pitfalls you found and which you deliberately left open. ## What you must not change - The existing public API and the behaviour of the calculator endpoints that currently work. - The database schema of existing tables (new tables/migrations are fine; renaming and deleting are not). - Other people's tests, seed data and existing values. If a change is necessary, put it in a separate commit and state it. If a change to an event's shape or a new consumer necessarily changes an existing test, update it in a separate commit and explain why in the summary. - Public contracts (APIs, event schemas) without backward compatibility. ## Done when - The test is reproducible: two runs with the same seed give the same fingerprint; the seed is in the test name. - Invariants are explicit (in code and in the README). - Open risks are in the README, each with a test; the fixed gap has a test that failed before the fix. - Tests pass with the existing test runner; lint and build pass if the project has them. - In the summary, state: what you changed, what you assumed, what remains.
Related parts of the presentation
Training for your team
Would you like this training for your team?
We run the training on your code and your domain problem. We agree the scope, dates and format with you.
Discuss the training