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.

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.

How the run unfolds (newest on top)

  1. 0.0 sMortgage Calculator APIcould not publish to the brokerMortgageApplicationSubmittedintegration

    publishing to the broker failed

    The event is stored, but nobody will learn about it: the process is stuck (dual write problem)

  2. 0.0 sMortgage Calculator APIappended to the event storeMortgageApplicationSubmittedintegration

    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
    }

    evt-0004 · correlationId calc-1 · causationId evt-0003

  3. 0.0 sMortgage Calculator APIappended to the event storeApplicationSubmitteddomain

    Event 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"
      }
    }

    evt-0003 · correlationId calc-1

  4. 0.0 sMortgage Calculator APIappended to the event storeCalculationCompleteddomain

    Event content
    {
      "algorithm": "v1",
      "result": {
        "loan": 5200000,
        "monthlyPayment": 29590,
        "dti": 0.34811764705882353,
        "ltv": 0.8,
        "algorithm": "v1"
      },
      "referenceNumber": "KALK-calc-1-2"
    }

    evt-0002 · correlationId calc-1

  5. 0.0 sMortgage Calculator APIappended to the event storeCalculationCreateddomain

    Event content
    {
      "calculationId": "calc-1",
      "monthlyIncome": 85000,
      "propertyPrice": 6500000,
      "downPaymentPct": 20,
      "ratePct": 5.49,
      "termYears": 30
    }

    evt-0001 · correlationId calc-1

Run chaos with all defences

The same conditions, but with defences enabled. The process completes consistently, just more slowly.

How the run unfolds (newest on top)

  1. 19.13 sProjection (read model)processedMortgageDisbursementRequestedcommand

  2. 18.9 sProjection (read model)picked upMortgageDisbursementRequestedcommand

    attempt 1

  3. 18.88 sProjection (read model)processedMortgageDisbursedintegration

  4. 18.88 sProjection (read model)bufferedMortgageDisbursedintegration

    waiting for corrSeq 11

  5. 18.58 sProjection (read model)picked upMortgageDisbursedintegration

    attempt 1

  6. 16.98 sProjection (read model)processedContractSignedintegration

  7. 16.7 sProjection (read model)picked upContractSignedintegration

    attempt 1

  8. 16.25 sProcess Manager (Saga)processedMortgageDisbursedintegration

  9. 15.93 sProcess Manager (Saga)picked upMortgageDisbursedintegration

    attempt 1

  10. 15.8 sDisbursementignored a duplicate (Inbox)MortgageDisbursementRequestedcommand

    Inbox: eventId already processed

  11. 15.5 sDisbursementsent from the OutboxMortgageDisbursedintegration

    sent on attempt 1

  12. 15.33 sProjection (read model)processedContractGenerationRequestedcommand

  13. 15.2 sDisbursementpicked upMortgageDisbursementRequestedcommand

    attempt 1

  14. 15.2 sDisbursementprocessedMortgageDisbursementRequestedcommand

  15. 15.2 sDisbursementstored in the OutboxMortgageDisbursedintegration

    for: Process Manager (Saga)Projection (read model)

    Event content
    {
      "amount": 5200000,
      "accountNumber": "0800-100017/0800"
    }

    evt-0052 · correlationId calc-1 · causationId evt-0047

  16. 14.98 sProjection (read model)picked upContractGenerationRequestedcommand

    attempt 1

  17. 14.98 sProjection (read model)processedMortgageAccountOpenedintegration

  18. 14.6 sProjection (read model)picked upMortgageAccountOpenedintegration

    attempt 1

  19. 14.55 sDisbursementpicked upMortgageDisbursementRequestedcommand

    attempt 1

  20. 14.18 sProcess Manager (Saga)sent from the OutboxMortgageDisbursementRequestedcommand

    sent on attempt 1

  21. 14.18 sDisbursementreceives the message twiceMortgageDisbursementRequestedcommand

    broker delivers the message 2×

  22. 13.88 sProcess Manager (Saga)processedContractSignedintegration

  23. 13.88 sProcess Manager (Saga)stored in the OutboxMortgageDisbursementRequestedcommand

    for: DisbursementProjection (read model)

    Event content
    {
      "applicationId": "calc-1",
      "amount": 5200000,
      "accountNumber": "0800-100017/0800",
      "customerId": "CUST-0001"
    }

    evt-0047 · correlationId calc-1 · causationId evt-0043

  24. 13.63 sProcess Manager (Saga)picked upContractSignedintegration

    attempt 1

  25. 13.18 sDocument Servicesent from the OutboxContractSignedintegration

    sent on attempt 1

  26. 12.88 sDocument Servicestored in the OutboxContractSignedintegration

    for: Process Manager (Saga)Projection (read model)

    Event content
    {
      "contractId": "SML-0001",
      "signedBy": "klient"
    }

    evt-0043 · correlationId calc-1 · causationId evt-0039

  27. 12.88 sProjection (read model)ignored a duplicate (Inbox)CustomerIdentityCreatedintegration

    Inbox: eventId already processed

  28. 12.5 sProjection (read model)picked upCustomerIdentityCreatedintegration

    attempt 1

  29. 12.38 sProjection (read model)processedContractGeneratedintegration

  30. 12.38 sProjection (read model)bufferedContractGeneratedintegration

    waiting for corrSeq 7

  31. 12.3 sProcess Manager (Saga)processedContractGeneratedintegration

  32. 12.05 sProjection (read model)picked upContractGeneratedintegration

    attempt 1

  33. 12.03 sProjection (read model)processedMortgageAccountOpeningRequestedcommand

  34. 11.98 sProcess Manager (Saga)picked upContractGeneratedintegration

    attempt 1

  35. 11.68 sProjection (read model)picked upMortgageAccountOpeningRequestedcommand

    attempt 1

  36. 11.65 sDocument Servicesent from the OutboxContractGeneratedintegration

    sent on attempt 1

  37. 11.35 sDocument ServiceprocessedContractGenerationRequestedcommand

  38. 11.35 sDocument Servicestored in the OutboxContractGeneratedintegration

    for: Process Manager (Saga)Projection (read model)

    Event content
    {
      "contractId": "SML-0001"
    }

    evt-0039 · correlationId calc-1 · causationId evt-0035

  39. 10.7 sDocument Servicepicked upContractGenerationRequestedcommand

    attempt 1

  40. 10.3 sProcess Manager (Saga)sent from the OutboxContractGenerationRequestedcommand

    sent on attempt 1

  41. 10.15 sProjection (read model)processedCustomerIdentityCreationRequestedcommand

  42. 10.0 sProcess Manager (Saga)processedMortgageAccountOpenedintegration

  43. 10.0 sProcess Manager (Saga)stored in the OutboxContractGenerationRequestedcommand

    for: Document ServiceProjection (read model)

    Event content
    {
      "applicationId": "calc-1",
      "amount": 5200000,
      "accountNumber": "0800-100017/0800",
      "customerId": "CUST-0001"
    }

    evt-0035 · correlationId calc-1 · causationId evt-0031

  44. 9.83 sProjection (read model)picked upCustomerIdentityCreationRequestedcommand

    attempt 1

  45. 9.75 sProcess Manager (Saga)picked upMortgageAccountOpenedintegration

    attempt 1

  46. 9.45 sProjection (read model)processedCustomerIdentityCreatedintegration

  47. 9.45 sProjection (read model)bufferedCustomerIdentityCreatedintegration

    waiting for corrSeq 4

  48. 9.33 sMortgage Accountsent from the OutboxMortgageAccountOpenedintegration

    sent on attempt 1

  49. 9.08 sProjection (read model)picked upCustomerIdentityCreatedintegration

    attempt 1

  50. 9.03 sMortgage AccountprocessedMortgageAccountOpeningRequestedcommand

  51. 9.03 sMortgage Accountstored in the OutboxMortgageAccountOpenedintegration

    for: Process Manager (Saga)Projection (read model)

    Event content
    {
      "accountNumber": "0800-100017/0800"
    }

    evt-0031 · correlationId calc-1 · causationId evt-0027

  52. 8.48 sProjection (read model)ignored a duplicate (Inbox)RiskAssessmentCompletedintegration

    Inbox: eventId already processed

  53. 8.4 sMortgage Accountpicked upMortgageAccountOpeningRequestedcommand

    attempt 1

  54. 8.23 sProjection (read model)picked upRiskAssessmentCompletedintegration

    attempt 1

  55. 7.98 sProcess Manager (Saga)sent from the OutboxMortgageAccountOpeningRequestedcommand

    sent on attempt 1

  56. 7.68 sProcess Manager (Saga)processedCustomerIdentityCreatedintegration

  57. 7.68 sProcess Manager (Saga)stored in the OutboxMortgageAccountOpeningRequestedcommand

    for: Mortgage AccountProjection (read model)

    Event content
    {
      "applicationId": "calc-1",
      "amount": 5200000,
      "customerId": "CUST-0001"
    }

    evt-0027 · correlationId calc-1 · causationId evt-0022

  58. 7.6 sProjection (read model)processedMortgageApprovedintegration

  59. 7.35 sProcess Manager (Saga)picked upCustomerIdentityCreatedintegration

    attempt 1

  60. 7.33 sProjection (read model)picked upMortgageApprovedintegration

    attempt 1

  61. 6.95 sCustomer Identitysent from the OutboxCustomerIdentityCreatedintegration

    sent on attempt 1

  62. 6.95 sProjection (read model)receives the message twiceCustomerIdentityCreatedintegration

    broker delivers the message 2×

  63. 6.65 sCustomer IdentityprocessedCustomerIdentityCreationRequestedcommand

  64. 6.65 sCustomer Identitystored in the OutboxCustomerIdentityCreatedintegration

    for: Process Manager (Saga)Projection (read model)

    Event content
    {
      "customerId": "CUST-0001"
    }

    evt-0022 · correlationId calc-1 · causationId evt-0018

  65. 6.05 sCustomer Identitypicked upCustomerIdentityCreationRequestedcommand

    attempt 1

  66. 5.7 sProcess Manager (Saga)sent from the OutboxCustomerIdentityCreationRequestedcommand

    sent on attempt 2

  67. 5.23 sProjection (read model)processedRiskAssessmentCompletedintegration

  68. 5.2 sProcess Manager (Saga)failed while processingCustomerIdentityCreationRequestedcommand

    relay: broker unavailable, attempt 1

  69. 4.9 sProcess Manager (Saga)processedMortgageApprovedintegration

  70. 4.9 sProcess Manager (Saga)stored in the OutboxCustomerIdentityCreationRequestedcommand

    for: Customer IdentityProjection (read model)

    Event content
    {
      "applicationId": "calc-1",
      "amount": 5200000
    }

    evt-0018 · correlationId calc-1 · causationId evt-0014

  71. 4.85 sProjection (read model)picked upRiskAssessmentCompletedintegration

    attempt 1

  72. 4.73 sProjection (read model)processedMortgageApplicationSubmittedintegration

  73. 4.53 sProcess Manager (Saga)picked upMortgageApprovedintegration

    attempt 1

  74. 4.38 sProjection (read model)picked upMortgageApplicationSubmittedintegration

    attempt 1

  75. 4.13 sApproval / Controllingsent from the OutboxMortgageApprovedintegration

    sent on attempt 1

  76. 3.83 sApproval / ControllingprocessedRiskAssessmentCompletedintegration

  77. 3.83 sApproval / Controllingstored in the OutboxMortgageApprovedintegration

    for: Process Manager (Saga)Projection (read model)

    Event content
    {
      "approvedAmount": 5200000,
      "score": 800
    }

    evt-0014 · correlationId calc-1 · causationId evt-0009

  78. 3.33 sApproval / Controllingpicked upRiskAssessmentCompletedintegration

    attempt 1

  79. 3.0 sRisk Servicesent from the OutboxRiskAssessmentCompletedintegration

    sent on attempt 2

  80. 3.0 sProjection (read model)receives the message twiceRiskAssessmentCompletedintegration

    broker delivers the message 2×

  81. 2.5 sRisk Servicefailed while processingRiskAssessmentCompletedintegration

    relay: broker unavailable, attempt 1

  82. 2.2 sRisk ServiceprocessedMortgageApplicationSubmittedintegration

  83. 2.2 sRisk Servicestored in the OutboxRiskAssessmentCompletedintegration

    for: Approval / ControllingProjection (read model)

    Event content
    {
      "score": 800,
      "loanAmount": 5200000,
      "monthlyIncome": 85000,
      "dti": 0.34811764705882353,
      "ltv": 0.8
    }

    evt-0009 · correlationId calc-1 · causationId evt-0004

  84. 1.93 sProcess Manager (Saga)processedMortgageApplicationSubmittedintegration

  85. 1.7 sRisk Servicepicked upMortgageApplicationSubmittedintegration

    attempt 1

  86. 1.65 sProcess Manager (Saga)picked upMortgageApplicationSubmittedintegration

    attempt 1

  87. 1.3 sMortgage Calculator APIsent from the OutboxMortgageApplicationSubmittedintegration

    sent on attempt 3

  88. 0.8 sMortgage Calculator APIfailed while processingMortgageApplicationSubmittedintegration

    relay: broker unavailable, attempt 2

  89. 0.3 sMortgage Calculator APIfailed while processingMortgageApplicationSubmittedintegration

    relay: broker unavailable, attempt 1

  90. 0.0 sMortgage Calculator APIstored in the OutboxMortgageApplicationSubmittedintegration

    for: 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
    }

    evt-0004 · correlationId calc-1 · causationId evt-0003

  91. 0.0 sMortgage Calculator APIappended to the event storeApplicationSubmitteddomain

    Event 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"
      }
    }

    evt-0003 · correlationId calc-1

  92. 0.0 sMortgage Calculator APIappended to the event storeCalculationCompleteddomain

    Event content
    {
      "algorithm": "v1",
      "result": {
        "loan": 5200000,
        "monthlyPayment": 29590,
        "dti": 0.34811764705882353,
        "ltv": 0.8,
        "algorithm": "v1"
      },
      "referenceNumber": "KALK-calc-1-2"
    }

    evt-0002 · correlationId calc-1

  93. 0.0 sMortgage Calculator APIappended to the event storeCalculationCreateddomain

    Event content
    {
      "calculationId": "calc-1",
      "monthlyIncome": 85000,
      "propertyPrice": 6500000,
      "downPaymentPct": 20,
      "ratePct": 5.49,
      "termYears": 30
    }

    evt-0001 · correlationId calc-1

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.

Language
Variant
# 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.

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