Exercise 14 · MortgageDisbursementRequested → MortgageDisbursed

Disbursement: offline service and backlog

  • service offline
  • backlog
  • timeout
  • double payout

Principle

When a subscriber is offline, the broker holds the messages. Once back, the service processes the backlog and nothing is lost. The sender does not know about the outage and carries on.

Watch out for the trap: the Process Manager has a timeout and resends the request after 4 s. Two payout requests for the same mortgage then wait in the queue.

Without an idempotent receiver, the bank pays out twice once the service is back. Retries and timeouts therefore always assume idempotency.

What to watch

  • Backlog at Disbursement (badge on the node).
  • Once the service is back (online button), both requests are processed.
  • Number of payouts in the service's local data.

Experiment

What to do: Click “Run outage (offline 12 s) + timeout”. What to look at: The client gets paid out twice.

The simulation needs JavaScript. Below is a recording of both runs.

Run outage (offline 12 s) + timeout

Disbursement is offline. After a timeout the saga resends the request. In 12 s the service comes back and processes the backlog.

How the run unfolds (newest on top)

  1. 14.3 sProjection (read model)processedMortgageDisbursedintegration

  2. 14.2 sProcess Manager (Saga)processedMortgageDisbursedintegration

  3. 14.2 sProcess Manager (Saga)ignored-stateMortgageDisbursedintegration

    krok disbursement is already done

  4. 13.93 sProjection (read model)picked upMortgageDisbursedintegration

    attempt 1

  5. 13.85 sProcess Manager (Saga)picked upMortgageDisbursedintegration

    attempt 1

  6. 13.58 sProjection (read model)processedMortgageDisbursedintegration

  7. 13.55 sProcess Manager (Saga)processedMortgageDisbursedintegration

  8. 13.48 sDisbursementprocessedMortgageDisbursementRequestedcommand

  9. 13.48 sDisbursementappended and publishedMortgageDisbursedintegration

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

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

    evt-0044 · correlationId calc-1 · causationId evt-0038

  10. 13.23 sProjection (read model)picked upMortgageDisbursedintegration

    attempt 1

  11. 13.23 sProjection (read model)processedMortgageDisbursementRequestedcommand

  12. 13.2 sProcess Manager (Saga)picked upMortgageDisbursedintegration

    attempt 1

  13. 12.95 sDisbursementpicked upMortgageDisbursementRequestedcommand

    attempt 1

  14. 12.93 sProjection (read model)picked upMortgageDisbursementRequestedcommand

    attempt 1

  15. 12.75 sDisbursementprocessedMortgageDisbursementRequestedcommand

  16. 12.75 sDisbursementappended and publishedMortgageDisbursedintegration

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

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

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

  17. 12.5 sProcess Manager (Saga)appended and publishedMortgageDisbursementRequestedcommand

    for: DisbursementProjection (read model)

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

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

  18. 12.0 sDisbursementpicked upMortgageDisbursementRequestedcommand

    attempt 1

  19. 9.2 sProjection (read model)processedMortgageDisbursementRequestedcommand

  20. 8.88 sProjection (read model)picked upMortgageDisbursementRequestedcommand

    attempt 1

  21. 8.55 sProjection (read model)processedContractSignedintegration

  22. 8.5 sProcess Manager (Saga)processedContractSignedintegration

  23. 8.5 sProcess Manager (Saga)appended and publishedMortgageDisbursementRequestedcommand

    for: DisbursementProjection (read model)

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

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

  24. 8.28 sProjection (read model)picked upContractSignedintegration

    attempt 1

  25. 8.23 sProcess Manager (Saga)picked upContractSignedintegration

    attempt 1

  26. 7.88 sDocument Serviceappended and publishedContractSignedintegration

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

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

    evt-0032 · correlationId calc-1 · causationId evt-0029

  27. 7.03 sProjection (read model)processedContractGeneratedintegration

  28. 6.95 sProcess Manager (Saga)processedContractGeneratedintegration

  29. 6.68 sProjection (read model)picked upContractGeneratedintegration

    attempt 1

  30. 6.63 sProcess Manager (Saga)picked upContractGeneratedintegration

    attempt 1

  31. 6.35 sDocument ServiceprocessedContractGenerationRequestedcommand

  32. 6.35 sDocument Serviceappended and publishedContractGeneratedintegration

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

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

    evt-0029 · correlationId calc-1 · causationId evt-0026

  33. 6.13 sProjection (read model)processedContractGenerationRequestedcommand

  34. 5.75 sProjection (read model)picked upContractGenerationRequestedcommand

    attempt 1

  35. 5.7 sDocument Servicepicked upContractGenerationRequestedcommand

    attempt 1

  36. 5.45 sProjection (read model)processedMortgageAccountOpenedintegration

  37. 5.33 sProcess Manager (Saga)processedMortgageAccountOpenedintegration

  38. 5.33 sProcess Manager (Saga)appended and publishedContractGenerationRequestedcommand

    for: Document ServiceProjection (read model)

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

    evt-0026 · correlationId calc-1 · causationId evt-0023

  39. 5.13 sProjection (read model)picked upMortgageAccountOpenedintegration

    attempt 1

  40. 4.98 sProcess Manager (Saga)picked upMortgageAccountOpenedintegration

    attempt 1

  41. 4.7 sMortgage AccountprocessedMortgageAccountOpeningRequestedcommand

  42. 4.7 sMortgage Accountappended and publishedMortgageAccountOpenedintegration

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

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

    evt-0023 · correlationId calc-1 · causationId evt-0020

  43. 4.45 sProjection (read model)processedMortgageAccountOpeningRequestedcommand

  44. 4.15 sMortgage Accountpicked upMortgageAccountOpeningRequestedcommand

    attempt 1

  45. 4.08 sProjection (read model)picked upMortgageAccountOpeningRequestedcommand

    attempt 1

  46. 3.88 sProjection (read model)processedCustomerIdentityCreatedintegration

  47. 3.75 sProcess Manager (Saga)processedCustomerIdentityCreatedintegration

  48. 3.75 sProcess Manager (Saga)appended and publishedMortgageAccountOpeningRequestedcommand

    for: Mortgage AccountProjection (read model)

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

    evt-0020 · correlationId calc-1 · causationId evt-0017

  49. 3.58 sProjection (read model)picked upCustomerIdentityCreatedintegration

    attempt 1

  50. 3.45 sProcess Manager (Saga)picked upCustomerIdentityCreatedintegration

    attempt 1

  51. 3.18 sCustomer IdentityprocessedCustomerIdentityCreationRequestedcommand

  52. 3.18 sCustomer Identityappended and publishedCustomerIdentityCreatedintegration

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

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

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

  53. 3.03 sProjection (read model)processedCustomerIdentityCreationRequestedcommand

  54. 2.7 sCustomer Identitypicked upCustomerIdentityCreationRequestedcommand

    attempt 1

  55. 2.68 sProjection (read model)picked upCustomerIdentityCreationRequestedcommand

    attempt 1

  56. 2.3 sProcess Manager (Saga)processedMortgageApprovedintegration

  57. 2.3 sProcess Manager (Saga)appended and publishedCustomerIdentityCreationRequestedcommand

    for: Customer IdentityProjection (read model)

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

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

  58. 2.23 sProjection (read model)processedMortgageApprovedintegration

  59. 1.98 sProjection (read model)picked upMortgageApprovedintegration

    attempt 1

  60. 1.95 sProcess Manager (Saga)picked upMortgageApprovedintegration

    attempt 1

  61. 1.65 sApproval / ControllingprocessedRiskAssessmentCompletedintegration

  62. 1.65 sApproval / Controllingappended and publishedMortgageApprovedintegration

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

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

    evt-0011 · correlationId calc-1 · causationId evt-0008

  63. 1.5 sProjection (read model)processedRiskAssessmentCompletedintegration

  64. 1.13 sProjection (read model)picked upRiskAssessmentCompletedintegration

    attempt 1

  65. 1.1 sApproval / Controllingpicked upRiskAssessmentCompletedintegration

    attempt 1

  66. 0.8 sRisk ServiceprocessedMortgageApplicationSubmittedintegration

  67. 0.8 sRisk Serviceappended and publishedRiskAssessmentCompletedintegration

    for: Approval / ControllingProjection (read model)

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

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

  68. 0.75 sProcess Manager (Saga)processedMortgageApplicationSubmittedintegration

  69. 0.68 sProjection (read model)processedMortgageApplicationSubmittedintegration

  70. 0.4 sProcess Manager (Saga)picked upMortgageApplicationSubmittedintegration

    attempt 1

  71. 0.35 sProjection (read model)picked upMortgageApplicationSubmittedintegration

    attempt 1

  72. 0.28 sRisk Servicepicked upMortgageApplicationSubmittedintegration

    attempt 1

  73. 0.0 sMortgage Calculator APIappended and publishedMortgageApplicationSubmittedintegration

    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

  74. 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

  75. 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

  76. 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 with idempotent receiver

A second request for the same application returns the original result and the money is paid out once.

How the run unfolds (newest on top)

  1. 14.3 sProjection (read model)processedMortgageDisbursedintegration

  2. 14.2 sProcess Manager (Saga)processedMortgageDisbursedintegration

  3. 14.2 sProcess Manager (Saga)ignored-stateMortgageDisbursedintegration

    krok disbursement is already done

  4. 13.93 sProjection (read model)picked upMortgageDisbursedintegration

    attempt 1

  5. 13.85 sProcess Manager (Saga)picked upMortgageDisbursedintegration

    attempt 1

  6. 13.58 sProjection (read model)processedMortgageDisbursedintegration

  7. 13.55 sProcess Manager (Saga)processedMortgageDisbursedintegration

  8. 13.48 sDisbursementprocessedMortgageDisbursementRequestedcommand

  9. 13.48 sDisbursementappended and publishedMortgageDisbursedintegration

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

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

    evt-0044 · correlationId calc-1 · causationId evt-0038

  10. 13.23 sProjection (read model)picked upMortgageDisbursedintegration

    attempt 1

  11. 13.23 sProjection (read model)processedMortgageDisbursementRequestedcommand

  12. 13.2 sProcess Manager (Saga)picked upMortgageDisbursedintegration

    attempt 1

  13. 12.95 sDisbursementpicked upMortgageDisbursementRequestedcommand

    attempt 1

  14. 12.93 sProjection (read model)picked upMortgageDisbursementRequestedcommand

    attempt 1

  15. 12.75 sDisbursementprocessedMortgageDisbursementRequestedcommand

  16. 12.75 sDisbursementappended and publishedMortgageDisbursedintegration

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

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

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

  17. 12.5 sProcess Manager (Saga)appended and publishedMortgageDisbursementRequestedcommand

    for: DisbursementProjection (read model)

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

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

  18. 12.0 sDisbursementpicked upMortgageDisbursementRequestedcommand

    attempt 1

  19. 9.2 sProjection (read model)processedMortgageDisbursementRequestedcommand

  20. 8.88 sProjection (read model)picked upMortgageDisbursementRequestedcommand

    attempt 1

  21. 8.55 sProjection (read model)processedContractSignedintegration

  22. 8.5 sProcess Manager (Saga)processedContractSignedintegration

  23. 8.5 sProcess Manager (Saga)appended and publishedMortgageDisbursementRequestedcommand

    for: DisbursementProjection (read model)

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

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

  24. 8.28 sProjection (read model)picked upContractSignedintegration

    attempt 1

  25. 8.23 sProcess Manager (Saga)picked upContractSignedintegration

    attempt 1

  26. 7.88 sDocument Serviceappended and publishedContractSignedintegration

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

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

    evt-0032 · correlationId calc-1 · causationId evt-0029

  27. 7.03 sProjection (read model)processedContractGeneratedintegration

  28. 6.95 sProcess Manager (Saga)processedContractGeneratedintegration

  29. 6.68 sProjection (read model)picked upContractGeneratedintegration

    attempt 1

  30. 6.63 sProcess Manager (Saga)picked upContractGeneratedintegration

    attempt 1

  31. 6.35 sDocument ServiceprocessedContractGenerationRequestedcommand

  32. 6.35 sDocument Serviceappended and publishedContractGeneratedintegration

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

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

    evt-0029 · correlationId calc-1 · causationId evt-0026

  33. 6.13 sProjection (read model)processedContractGenerationRequestedcommand

  34. 5.75 sProjection (read model)picked upContractGenerationRequestedcommand

    attempt 1

  35. 5.7 sDocument Servicepicked upContractGenerationRequestedcommand

    attempt 1

  36. 5.45 sProjection (read model)processedMortgageAccountOpenedintegration

  37. 5.33 sProcess Manager (Saga)processedMortgageAccountOpenedintegration

  38. 5.33 sProcess Manager (Saga)appended and publishedContractGenerationRequestedcommand

    for: Document ServiceProjection (read model)

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

    evt-0026 · correlationId calc-1 · causationId evt-0023

  39. 5.13 sProjection (read model)picked upMortgageAccountOpenedintegration

    attempt 1

  40. 4.98 sProcess Manager (Saga)picked upMortgageAccountOpenedintegration

    attempt 1

  41. 4.7 sMortgage AccountprocessedMortgageAccountOpeningRequestedcommand

  42. 4.7 sMortgage Accountappended and publishedMortgageAccountOpenedintegration

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

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

    evt-0023 · correlationId calc-1 · causationId evt-0020

  43. 4.45 sProjection (read model)processedMortgageAccountOpeningRequestedcommand

  44. 4.15 sMortgage Accountpicked upMortgageAccountOpeningRequestedcommand

    attempt 1

  45. 4.08 sProjection (read model)picked upMortgageAccountOpeningRequestedcommand

    attempt 1

  46. 3.88 sProjection (read model)processedCustomerIdentityCreatedintegration

  47. 3.75 sProcess Manager (Saga)processedCustomerIdentityCreatedintegration

  48. 3.75 sProcess Manager (Saga)appended and publishedMortgageAccountOpeningRequestedcommand

    for: Mortgage AccountProjection (read model)

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

    evt-0020 · correlationId calc-1 · causationId evt-0017

  49. 3.58 sProjection (read model)picked upCustomerIdentityCreatedintegration

    attempt 1

  50. 3.45 sProcess Manager (Saga)picked upCustomerIdentityCreatedintegration

    attempt 1

  51. 3.18 sCustomer IdentityprocessedCustomerIdentityCreationRequestedcommand

  52. 3.18 sCustomer Identityappended and publishedCustomerIdentityCreatedintegration

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

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

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

  53. 3.03 sProjection (read model)processedCustomerIdentityCreationRequestedcommand

  54. 2.7 sCustomer Identitypicked upCustomerIdentityCreationRequestedcommand

    attempt 1

  55. 2.68 sProjection (read model)picked upCustomerIdentityCreationRequestedcommand

    attempt 1

  56. 2.3 sProcess Manager (Saga)processedMortgageApprovedintegration

  57. 2.3 sProcess Manager (Saga)appended and publishedCustomerIdentityCreationRequestedcommand

    for: Customer IdentityProjection (read model)

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

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

  58. 2.23 sProjection (read model)processedMortgageApprovedintegration

  59. 1.98 sProjection (read model)picked upMortgageApprovedintegration

    attempt 1

  60. 1.95 sProcess Manager (Saga)picked upMortgageApprovedintegration

    attempt 1

  61. 1.65 sApproval / ControllingprocessedRiskAssessmentCompletedintegration

  62. 1.65 sApproval / Controllingappended and publishedMortgageApprovedintegration

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

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

    evt-0011 · correlationId calc-1 · causationId evt-0008

  63. 1.5 sProjection (read model)processedRiskAssessmentCompletedintegration

  64. 1.13 sProjection (read model)picked upRiskAssessmentCompletedintegration

    attempt 1

  65. 1.1 sApproval / Controllingpicked upRiskAssessmentCompletedintegration

    attempt 1

  66. 0.8 sRisk ServiceprocessedMortgageApplicationSubmittedintegration

  67. 0.8 sRisk Serviceappended and publishedRiskAssessmentCompletedintegration

    for: Approval / ControllingProjection (read model)

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

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

  68. 0.75 sProcess Manager (Saga)processedMortgageApplicationSubmittedintegration

  69. 0.68 sProjection (read model)processedMortgageApplicationSubmittedintegration

  70. 0.4 sProcess Manager (Saga)picked upMortgageApplicationSubmittedintegration

    attempt 1

  71. 0.35 sProjection (read model)picked upMortgageApplicationSubmittedintegration

    attempt 1

  72. 0.28 sRisk Servicepicked upMortgageApplicationSubmittedintegration

    attempt 1

  73. 0.0 sMortgage Calculator APIappended and publishedMortgageApplicationSubmittedintegration

    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

  74. 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

  75. 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

  76. 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.

17 events · 14.3 s of simulated time

Cause → effect

  • MortgageDisbursementRequested processed a second time without idempotency → DOUBLE PAYOUT: PAY-0002, the bank sent 5,200,000 CZK a second time MortgageDisbursementRequested

17 events · 14.3 s of simulated time

Cause → effect

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.

Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

Language
Variant
# Task for a coding agent: Disbursement: offline service and backlog

Stack: Java. Mode: guided.
Goal: Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

## 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 an asynchronous application flow up to the contract. If the payout is only a synchronous call, first set up a minimal step: contract message (`LoanContractGenerated`) → disbursement consumer → service → `DisbursementScheduled`.

Read first, change nothing. Find and briefly summarise:
- How messages for the disbursement service are persisted (broker, queue), where the timeouts are and how long an outage the retry policy survives.
- Whether the payout is protected by a business key (applicationId) or an idempotency key.
- Monitoring: who finds out about a growing queue.
- Which of these parts already exist in the project and which are missing. Before writing your own infrastructure (retry, rate limiting, queue monitoring), 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

An offline disbursement service, once back, processes the backlog the broker held. The trap: after a timeout the sender resends the request; without an idempotent receiver the payout happens twice once the service is back. So every attempt carries the same idempotency key. Example: an attempt times out, yet the service records it; the retry with the same key gets the original payout (`200`), not a second one.

## Specific task

Technical specifics (Java): Unique index on `(application_id, step)`, listener with limited concurrency.

Proceed step by step. After point 1 (plan), write what you found and what you propose, and wait for confirmation:
1. Plan: draw what happens during a 30 s outage (queue, timeout, retries).
2. Introduce an idempotency key `<applicationId>:<process step>` (e.g. `…:disbursement`) with a unique constraint in the disbursement service, in one transaction with the payout. Calls without a key stay unchanged.
3. One policy in one place (attempt timeout, backoff, retry window, rate limit, alarm threshold), shortened in tests. Log a failed attempt as an operational event (failure kind, next attempt or DLQ).
4. Alarm on the age of the oldest message in the queue: threshold longer than the attempt with the longest backoff, shorter than the time to DLQ.
5. Integration test: offline → a request the service processes only after the client timeout → online → exactly one payout. Control: without the key, two payouts.

Watch out for:
- A timeout shorter than the usual processing time produces duplicates on its own.
- When the service comes back, it processes the whole backlog at once: limit the rate, retries included.
- An in-memory broker does not protect against a consumer outage; state this 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

- Integration test with an outage and a late-processed request; control test without the key.
- Unique constraint on the idempotency key in the disbursement service.
- Alarm on queue age and a rate limit.
- 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: Disbursement: offline service and backlog

Stack: Java. Mode: challenge.
Goal: Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

## 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 an asynchronous application flow up to the contract. If the payout is only a synchronous call, first set up a minimal step: contract message (`LoanContractGenerated`) → disbursement consumer → service → `DisbursementScheduled`.

Read first, change nothing. Find and briefly summarise:
- How messages for the disbursement service are persisted (broker, queue), where the timeouts are and how long an outage the retry policy survives.
- Whether the payout is protected by a business key (applicationId) or an idempotency key.
- Monitoring: who finds out about a growing queue.
- Which of these parts already exist in the project and which are missing. Before writing your own infrastructure (retry, rate limiting, queue monitoring), 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

An offline disbursement service, once back, processes the backlog the broker held. The trap: after a timeout the sender resends the request; without an idempotent receiver the payout happens twice once the service is back. So every attempt carries the same idempotency key. Example: an attempt times out, yet the service records it; the retry with the same key gets the original payout (`200`), not a second one.

## Brief (Challenge)

Prove with a test that after a disbursement service outage and a retried request, exactly one payout is made.

Technical specifics (Java): Unique index on `(application_id, step)`, listener with limited concurrency.

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

- Integration test with an outage and a late-processed request; control test without the key.
- Unique constraint on the idempotency key in the disbursement service.
- Alarm on queue age and a rate limit.
- 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: Disbursement: offline service and backlog

Stack: C#. Mode: guided.
Goal: Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

## 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 an asynchronous application flow up to the contract. If the payout is only a synchronous call, first set up a minimal step: contract message (`LoanContractGenerated`) → disbursement consumer → service → `DisbursementScheduled`.

Read first, change nothing. Find and briefly summarise:
- How messages for the disbursement service are persisted (broker, queue), where the timeouts are and how long an outage the retry policy survives.
- Whether the payout is protected by a business key (applicationId) or an idempotency key.
- Monitoring: who finds out about a growing queue.
- Which of these parts already exist in the project and which are missing. Before writing your own infrastructure (retry, rate limiting, queue monitoring), 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

An offline disbursement service, once back, processes the backlog the broker held. The trap: after a timeout the sender resends the request; without an idempotent receiver the payout happens twice once the service is back. So every attempt carries the same idempotency key. Example: an attempt times out, yet the service records it; the retry with the same key gets the original payout (`200`), not a second one.

## Specific task

Technical specifics (C#): Unique index, consumer with `PrefetchCount`/`ConcurrentMessageLimit`.

Proceed step by step. After point 1 (plan), write what you found and what you propose, and wait for confirmation:
1. Plan: draw what happens during a 30 s outage (queue, timeout, retries).
2. Introduce an idempotency key `<applicationId>:<process step>` (e.g. `…:disbursement`) with a unique constraint in the disbursement service, in one transaction with the payout. Calls without a key stay unchanged.
3. One policy in one place (attempt timeout, backoff, retry window, rate limit, alarm threshold), shortened in tests. Log a failed attempt as an operational event (failure kind, next attempt or DLQ).
4. Alarm on the age of the oldest message in the queue: threshold longer than the attempt with the longest backoff, shorter than the time to DLQ.
5. Integration test: offline → a request the service processes only after the client timeout → online → exactly one payout. Control: without the key, two payouts.

Watch out for:
- A timeout shorter than the usual processing time produces duplicates on its own.
- When the service comes back, it processes the whole backlog at once: limit the rate, retries included.
- An in-memory broker does not protect against a consumer outage; state this 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

- Integration test with an outage and a late-processed request; control test without the key.
- Unique constraint on the idempotency key in the disbursement service.
- Alarm on queue age and a rate limit.
- 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: Disbursement: offline service and backlog

Stack: C#. Mode: challenge.
Goal: Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

## 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 an asynchronous application flow up to the contract. If the payout is only a synchronous call, first set up a minimal step: contract message (`LoanContractGenerated`) → disbursement consumer → service → `DisbursementScheduled`.

Read first, change nothing. Find and briefly summarise:
- How messages for the disbursement service are persisted (broker, queue), where the timeouts are and how long an outage the retry policy survives.
- Whether the payout is protected by a business key (applicationId) or an idempotency key.
- Monitoring: who finds out about a growing queue.
- Which of these parts already exist in the project and which are missing. Before writing your own infrastructure (retry, rate limiting, queue monitoring), 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

An offline disbursement service, once back, processes the backlog the broker held. The trap: after a timeout the sender resends the request; without an idempotent receiver the payout happens twice once the service is back. So every attempt carries the same idempotency key. Example: an attempt times out, yet the service records it; the retry with the same key gets the original payout (`200`), not a second one.

## Brief (Challenge)

Prove with a test that after a disbursement service outage and a retried request, exactly one payout is made.

Technical specifics (C#): Unique index, consumer with `PrefetchCount`/`ConcurrentMessageLimit`.

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

- Integration test with an outage and a late-processed request; control test without the key.
- Unique constraint on the idempotency key in the disbursement service.
- Alarm on queue age and a rate limit.
- 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: Disbursement: offline service and backlog

Stack: Web (HTML/JS or the app's stack). Mode: guided.
Goal: Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

## 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 an asynchronous application flow up to the contract. If the payout is only a synchronous call, first set up a minimal step: contract message (`LoanContractGenerated`) → disbursement consumer → service → `DisbursementScheduled`.

Read first, change nothing. Find and briefly summarise:
- How messages for the disbursement service are persisted (broker, queue), where the timeouts are and how long an outage the retry policy survives.
- Whether the payout is protected by a business key (applicationId) or an idempotency key.
- Monitoring: who finds out about a growing queue.
- Which of these parts already exist in the project and which are missing. Before writing your own infrastructure (retry, rate limiting, queue monitoring), 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

An offline disbursement service, once back, processes the backlog the broker held. The trap: after a timeout the sender resends the request; without an idempotent receiver the payout happens twice once the service is back. So every attempt carries the same idempotency key. Example: an attempt times out, yet the service records it; the retry with the same key gets the original payout (`200`), not a second one.

## Specific task

Technical specifics (Web (HTML/JS or the app's stack)): With a backend, the disbursement consumer runs on the server and the UI only reads the “payout pending” state; without a backend, a queue in IndexedDB. Never retry a command without an idempotency key.

Proceed step by step. After point 1 (plan), write what you found and what you propose, and wait for confirmation:
1. Plan: draw what happens during a 30 s outage (queue, timeout, retries).
2. Introduce an idempotency key `<applicationId>:<process step>` (e.g. `…:disbursement`) with a unique constraint in the disbursement service, in one transaction with the payout. Calls without a key stay unchanged.
3. One policy in one place (attempt timeout, backoff, retry window, rate limit, alarm threshold), shortened in tests. Log a failed attempt as an operational event (failure kind, next attempt or DLQ).
4. Alarm on the age of the oldest message in the queue: threshold longer than the attempt with the longest backoff, shorter than the time to DLQ.
5. Integration test: offline → a request the service processes only after the client timeout → online → exactly one payout. Control: without the key, two payouts.

Watch out for:
- A timeout shorter than the usual processing time produces duplicates on its own.
- When the service comes back, it processes the whole backlog at once: limit the rate, retries included.
- An in-memory broker does not protect against a consumer outage; state this 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

- Integration test with an outage and a late-processed request; control test without the key.
- Unique constraint on the idempotency key in the disbursement service.
- Alarm on queue age and a rate limit.
- 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: Disbursement: offline service and backlog

Stack: Web (HTML/JS or the app's stack). Mode: challenge.
Goal: Ensure that a disbursement service outage (not running, or responding late) neither loses a request nor causes a double payout once it is back.

## 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 an asynchronous application flow up to the contract. If the payout is only a synchronous call, first set up a minimal step: contract message (`LoanContractGenerated`) → disbursement consumer → service → `DisbursementScheduled`.

Read first, change nothing. Find and briefly summarise:
- How messages for the disbursement service are persisted (broker, queue), where the timeouts are and how long an outage the retry policy survives.
- Whether the payout is protected by a business key (applicationId) or an idempotency key.
- Monitoring: who finds out about a growing queue.
- Which of these parts already exist in the project and which are missing. Before writing your own infrastructure (retry, rate limiting, queue monitoring), 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

An offline disbursement service, once back, processes the backlog the broker held. The trap: after a timeout the sender resends the request; without an idempotent receiver the payout happens twice once the service is back. So every attempt carries the same idempotency key. Example: an attempt times out, yet the service records it; the retry with the same key gets the original payout (`200`), not a second one.

## Brief (Challenge)

Prove with a test that after a disbursement service outage and a retried request, exactly one payout is made.

Technical specifics (Web (HTML/JS or the app's stack)): With a backend, the disbursement consumer runs on the server and the UI only reads the “payout pending” state; without a backend, a queue in IndexedDB. Never retry a command without an idempotency key.

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

- Integration test with an outage and a late-processed request; control test without the key.
- Unique constraint on the idempotency key in the disbursement service.
- Alarm on queue age and a rate limit.
- 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