University Fees: 5,000 Students
5,000 students owe ₹80,000 each. Trace partial payments, a lost browser response, duplicate webhooks and the final private receipt.
Illustrative production scenario — fictional educational records
1. Business Scenario
The payment window is 1–10 September in this illustrative semester. The maximum billed amount is 5,000 × ₹80,000 = ₹400,000,000 = ₹40 crore. A deadline policy may allow a late payment; it must be an explicit university decision, not a hidden change to history.
Rahul's invoice 5001 already has ₹30,000 confirmed and ₹50,000 remaining. His main request is Pay ₹50,000, not Pay ₹80,000 again. Priya's invoice is fully paid. Amit's unpaid ₹80,000 invoice is the separate browser-closed example.
The application must handle simultaneous students, double clicks, repeated callbacks, partial payment, unknown gateway outcomes, receipts and daily settlement differences. All identities and payment references here are fictional teaching records.
| Reference | Amount per main request | Scope |
|---|---|---|
| PAY-100502 | ₹50,000 | External outcome plus local allocation |
2. Real Database Tables
These are educational schema definitions, not tables to add to the job portal's live database. PK means primary key; FK means a foreign key to the named parent. Use DECIMAL(19,2) for stored money and integer minor units or decimal-safe arithmetic in application code.
Use MySQL InnoDB for these row-locking examples. NOT NULL, foreign keys and scoped UNIQUE constraints complement application validation. Monetary CHECK constraints require an engine/version that enforces them; the service must still reject invalid amounts.
students
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| student_no | VARCHAR(30) UNIQUE |
| name | VARCHAR(100) |
| course_id | VARCHAR(30) |
| semester | SMALLINT |
| status | VARCHAR(20) |
course_id refers to the institution's course catalog.
fee_structures
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| course_id | VARCHAR(30) |
| semester | SMALLINT |
| academic_year | VARCHAR(10) |
| total_amount | DECIMAL(19,2) |
| due_from | DATE |
| due_to | DATE |
UNIQUE(course_id, semester, academic_year). Invoice amounts are snapshots; changing a structure does not rewrite issued invoices.
student_fee_invoices
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| student_id | BIGINT FK students.id |
| invoice_no | VARCHAR(60) UNIQUE |
| gross_amount | DECIMAL(19,2) |
| discount_amount | DECIMAL(19,2) |
| net_amount | DECIMAL(19,2) |
| paid_amount | DECIMAL(19,2) |
| balance_amount | DECIMAL(19,2) |
| status | VARCHAR(30) |
| due_date | DATE |
Validate net = gross - discount and balance = net - allocated paid amount. Refunds/credits need explicit allocation records.
payments
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| student_id | BIGINT FK |
| invoice_id | BIGINT FK |
| payment_reference | VARCHAR(100) UNIQUE |
| gateway_reference | VARCHAR(100) NULL UNIQUE |
| amount | DECIMAL(19,2) |
| currency | CHAR(3) |
| status | VARCHAR(30) |
| payment_method | VARCHAR(30) |
| paid_at | TIMESTAMP NULL |
| failure_code | VARCHAR(100) NULL |
| idempotency_key | VARCHAR(100) UNIQUE |
Scope provider references by provider/merchant in a multi-provider system. Verify callback signature, saved amount, currency and intent.
receipts
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| payment_id | BIGINT UNIQUE FK payments.id |
| receipt_no | VARCHAR(60) UNIQUE |
| amount | DECIMAL(19,2) |
| generated_at | TIMESTAMP NULL |
| file_path | VARCHAR(255) NULL |
| status | VARCHAR(20) |
Receipt amount equals this payment, not the lifetime invoice total. Queue generation after commit; files are private.
audit_logs
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| user_id | BIGINT NULL (system actors allowed) |
| action | VARCHAR(60) |
| entity_type | VARCHAR(60) |
| entity_id | BIGINT |
| old_status | VARCHAR(30) NULL |
| new_status | VARCHAR(30) |
| metadata | JSON redacted |
| created_at | TIMESTAMP |
Append-only access policy; timestamps and actor identity explain who changed a result. Avoid full bank details or secrets in metadata.
outbox_events
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| event_key | VARCHAR(150) UNIQUE |
| aggregate_reference | VARCHAR(100) |
| event_type | VARCHAR(60) |
| payload | JSON |
| created_at | TIMESTAMP |
| published_at | TIMESTAMP NULL |
Write in the financial transaction; a dispatcher retries unpublished events. Consumers also deduplicate because queue delivery may repeat.
3. Sample Table Data
The rows below are fictional starting records. NULL means no confirmed value is known. Empty ledger/document tables are intentional before processing; their inserted records appear in Final Database State.
Large-population examples show representative rows, not all 2,000 or 10,000 records. Run totals refer to the complete illustrative population, not the displayed subset.
| id | student_no | name | course_id | semester | status |
|---|---|---|---|---|---|
| 101 | STU1001 | Rahul Sharma | BTECH-CS | 6 | ACTIVE |
| 102 | STU1002 | Priya Singh | BTECH-CS | 6 | ACTIVE |
| 103 | STU1003 | Amit Kumar | BCA | 4 | ACTIVE |
| id | course_id | semester | academic_year | total_amount | due_from | due_to |
|---|---|---|---|---|---|---|
| 60 | BTECH-CS | 6 | 2026-27 | 80000.00 | 2026-09-01 | 2026-09-10 |
| id | student_id | invoice_no | gross_amount | discount_amount | net_amount | paid_amount | balance_amount | status | due_date |
|---|---|---|---|---|---|---|---|---|---|
| 5001 | 101 | INV-2026-5001 | 80000.00 | 0.00 | 80000.00 | 30000.00 | 50000.00 | PARTIALLY_PAID | 2026-09-10 |
| 5002 | 102 | INV-2026-5002 | 80000.00 | 0.00 | 80000.00 | 80000.00 | 0.00 | PAID | 2026-09-10 |
| 5003 | 103 | INV-2026-5003 | 80000.00 | 0.00 | 80000.00 | 0.00 | 80000.00 | UNPAID | 2026-09-10 |
| id | student_id | invoice_id | payment_reference | gateway_reference | amount | currency | status | payment_method | paid_at | failure_code | idempotency_key |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 100501 | 101 | 5001 | PAY-100501 | GW-001 | 30000.00 | INR | SUCCESS | UPI | 2026-09-05 10:00:00 | NULL | FEE-5001-A |
| 100502 | 101 | 5001 | PAY-100502 | NULL | 50000.00 | INR | PENDING | UPI | NULL | NULL | FEE-5001-B |
| id | payment_id | receipt_no | amount | generated_at | file_path | status |
|---|---|---|---|---|---|---|
| 501 | 100501 | REC-2026-000501 | 30000.00 | 2026-09-05 10:01:00 | private/receipts/501.pdf | GENERATED |
| event_key | published_at |
|---|---|
| No rows yet — this is the state before processing. | |
4. User Action / Request
The request is a business intent, not an instruction to trust browser-supplied status, owner or balance. The controller authorizes the actor, validates shape and currency, and resolves the saved obligation.
Button click to recorded result
- Student STU1001
- Invoice 5001: due 50000
- Controller: Pay ₹50,000
- Persist payment intent 100502
- Gateway charges saved amount
- Verified backend webhook
- Allocate once to invoice
- COMMIT
- Receipt / notification queue
| Field | Value / rule |
|---|---|
| reference | PAY-100502 |
| amount | ₹50,000; validate against saved request |
| authenticated actor | GATEWAY-WEBHOOK |
| response | Return saved result on duplicate; show pending while unresolved |
5. What Happens Inside the Application
The controller authorizes the student/invoice relationship and validates the requested amount against the invoice. It creates a unique payment intent before invoking the gateway. A double click with the same key returns the same intent; two different keys must not silently reserve or charge more than the remaining invoice.
The bank/gateway call runs outside a held invoice transaction. Treat the browser return as presentation only. A signed callback or provider status query supplies the external result; match merchant, payment reference, amount and INR currency to the intent.
The callback handler locks payment 100502 then invoice 5001. If the payment is already SUCCESS, return without another allocation. Save the confirmed gateway reference, update the invoice once, and create an audit event plus receipt outbox event in one local transaction. Verified external money with an allocation mismatch must remain traceable in an exception workflow.
Application responsibility boundaries
- Request
- Controller: authorize / validate
- Service: business rules / idempotency
- Database: locks / constraints / atomic writes
- Adapter: external protocol
- Callback / reconciler: verify evidence
- Outbox and document worker
6. Database Transaction
Transaction boundaries
- Verify callback signature and saved intent
- BEGIN
- Lock payments 100502
- If SUCCESS: return recorded result
- Lock invoice 5001
- Check verified amount 50000 and balance 50000
- Allocate, mark payment SUCCESS, invoice PAID
- Create pending receipt / audit / outbox
- COMMIT
Atomicity applies to the writes enclosed by one BEGIN/COMMIT. Consistency means the amount, status, ledger/allocation and audit invariants agree. Isolation prevents conflicting decisions on locked rows. Durability means a committed result survives a client disconnect.
On unexpected database errors, roll back the local transaction. A known business rejection can instead be recorded and committed without a financial mutation. Never swallow a database exception and accidentally commit half of the intended changes.
Do not hold an invoice/account/item lock across bank network calls. Persist the intent first, commit it, then call the adapter. Apply verified results in a new short transaction. A database rollback cannot recall money already moved by an external bank.
7. SQL Query
SQL fragments show the successful branch of an application-controlled transaction. Comments describing checks are real control-flow requirements: the handler must stop/rollback or record the specified exception when a guard fails. Do not paste all branches as one unconditional money-moving script.
Representative SQL and guarded updates
START TRANSACTION;
SELECT id, invoice_id, amount, currency, status FROM payments WHERE id = 100502 FOR UPDATE;
SELECT id, net_amount, paid_amount, balance_amount FROM student_fee_invoices WHERE id = 5001 FOR UPDATE;
-- Handler has verified the gateway event; stop if payment is already SUCCESS.
-- Execute the allocation branch ONLY if the locked balance >= verified amount.
UPDATE student_fee_invoices SET
paid_amount = paid_amount + 50000.00,
balance_amount = balance_amount - 50000.00
WHERE id = 5001 AND balance_amount >= 50000.00;
-- Handler checks exactly one row changed; otherwise roll back local allocation
-- and persist the external confirmation as a reconciliation exception.
UPDATE student_fee_invoices SET status = CASE WHEN balance_amount = 0 THEN 'PAID' ELSE 'PARTIALLY_PAID' END WHERE id = 5001;
UPDATE payments SET gateway_reference = 'GW-002', status = 'SUCCESS', paid_at = '2026-09-28 10:00:00' WHERE id = 100502;
INSERT INTO receipts (id, payment_id, receipt_no, amount, status)
VALUES (502, 100502, 'REC-2026-000502', 50000.00, 'PENDING');
-- Audit and receipt outbox event are inserted before COMMIT.
COMMIT;
Use prepared parameters in application code; literal IDs are used here only so learners can track the sample rows. Verify affected-row counts before the next financial write. Unique-reference violations require inspection of the existing saved outcome, not a new debit.
8. Concurrent Request Scenario
| Time | Request / worker A | Request / worker B or external system |
|---|---|---|
| T0 | Webhook 1 for GW-002 locks payment 100502 | Webhook 2 for GW-002 arrives |
| T1 | Lock invoice; allocate 50000 | Wait for payment row lock |
| T2 | Payment SUCCESS; invoice PAID; COMMIT | Acquire lock; see SUCCESS |
| T3 | Receipt outbox event recorded once | Return acknowledgement; no second allocation |
| T4 | Webhook 3 sees saved SUCCESS | No extra receipt or invoice increment |
A waiting worker must re-read the row after it obtains the lock. A value read before waiting cannot authorize a later debit/allocation. A second delivery of one business request differs from a genuinely new request: the former returns the same outcome, while the latter must recheck current funds or remaining obligation.
9. Locking / Isolation
SELECT ... FOR UPDATE is a locking read inside an explicit InnoDB transaction. The row remains protected until COMMIT or ROLLBACK. Use indexed primary/unique lookups so the operation does not scan and lock unrelated data.
Every handler touching multiple entities must follow the same lock hierarchy. Define it once for workers, callbacks and reconcilers; opposite order can create deadlocks. A deadlock victim must restart the whole local transaction and re-read data.
Lock the saved business request/payment first, then its mutable account/invoice/item. Keep the transaction short and use current locked values, even if an earlier page showed a different balance.
Lock lifetime
- BEGIN
- Indexed locking read
- Validate current row
- Guarded mutation
- COMMIT / ROLLBACK
- Lock released
10. Calculation
| Value | Calculation / expected result |
|---|---|
| Potential collection | 5000 × 80000 = 400000000 (₹40 crore) |
| Rahul before | paid 30000; due 50000 |
| Confirmed payment | 50000 |
| Rahul after | paid 30000 + 50000 = 80000; due 0 |
Amounts shown in tables use two decimal places; commas and ₹ are display formatting, not database values. Round according to the documented currency/payroll rule once at the defined boundary. Do not add salary strings using floating-point arithmetic or silently change approved historical totals.
11. Table Update — Before / After
| Table or field | Before | After |
|---|---|---|
| invoice 5001 paid_amount | 30000.00 | 80000.00 |
| invoice 5001 balance_amount | 50000.00 | 0.00 |
| invoice 5001 status | PARTIALLY_PAID | PAID |
| payment 100502 | PENDING | SUCCESS / GW-002 |
| receipt 502 | Absent | PENDING then GENERATED |
The after rows describe only committed outcomes. A rollback preserves the before financial rows; a separately committed failure/audit record can still describe the rejected request. Background document status changes do not rewrite the financial success.
12. Status Transition
Success branch
- INITIATED / READY
- SUBMITTED
- PENDING / PROCESSING
- Verified SUCCESS
Failure / investigation branch
- SUBMITTED
- Timeout → UNKNOWN
- Query / callback / reconcile
- Verified SUCCESS or confirmed FAILED
Refund branch
- SUCCESS
- Authorized REFUND_REQUESTED
- Provider confirmation
- REFUNDED; retain original payment
| State | Meaning |
|---|---|
| READY / INITIATED | Saved intent; not proof of bank receipt |
| SUBMITTED | Send attempted; bank outcome not yet final |
| PENDING / PROCESSING | Provider confirms work in progress |
| UNKNOWN | No reliable external final outcome yet |
| SUCCESS | Verified final external success applied once locally |
| FAILED | Confirmed rejection; no blind assumption on timeout |
| REFUND_REQUESTED / REFUNDED | Separate authorized refund workflow with its own result |
13. Success Flow
Success means the defined financial operation and its associated local records are committed. Return the persisted reference and outcome to the client; do not generate a new success on each retry.
Record verified provider/bank evidence before releasing a success notification. A merely submitted request stays pending or unknown until evidence resolves it.
Committed success to user
- Saved financial result
- COMMIT
- Outbox dispatcher
- Idempotent document job
- Private document ready
- Notification / authorized download
14. Failure Flow
For Amit's independent unpaid invoice 5003, the gateway charges ₹80,000 but the browser closes before success returns. The backend keeps PENDING/UNKNOWN until a verified webhook or query confirms the result. Then it records SUCCESS and PAID; it never treats a browser disconnect as bank failure. A declined payment has confirmed FAILED and leaves invoice 5003 unchanged.
| Failure | Local action | Financial interpretation |
|---|---|---|
| Negative amount / invalid payload | REJECTED before submission | No financial operation |
| Insufficient funds / inactive entity | Record confirmed business failure | No local debit |
| Database error before external send | ROLLBACK | Retry only the rolled-back operation |
| Verified ACCOUNT_CLOSED | FAILED | Confirmed external rejection |
| BANK_TIMEOUT / lost response | UNKNOWN; investigate | May already have succeeded |
| PDF / email error | Retry document/notification only | Payment remains SUCCESS |
₹80,000 charge, browser closed
- Amit: invoice 5003 unpaid ₹80,000
- Gateway charges ₹80,000
- Browser closes — no frontend success
- Verified gateway webhook
- Backend locks payment and invoice
- Payment SUCCESS / invoice PAID
- Commit and receipt queue
| Confirmed amount | Invoice obligation | Excess | Controlled outcome |
|---|---|---|---|
| 90000.00 | 80000.00 | 10000.00 | OPEN exception → authorized refund / customer credit / allocation |
If the provider confirms ₹90,000 for an ₹80,000 obligation, keep the full external receipt traceable. Do not erase ₹10,000 or falsely call the whole payment failed. Capture an exception and resolve the excess through explicit ledger/credit/refund records, authorized business rules and provider references.
15. Retry Flow
Repeat a status query or process the signed callback with the original PAY-100502 / FEE-5001-B identity. A duplicate notification does not create another payment. If the gateway definitively failed without charging, a customer-authorized new attempt may be recorded according to provider rules, linked to the original intent.
Safe retry decision
- Find original saved reference
- Was any external request sent?
- Yes / uncertain → query original provider reference
- Confirmed success → return; never repeat effect
- Confirmed safe failure → bounded authorized retry
- Exhausted / unresolved → investigation queue
Use bounded exponential backoff for transient technical errors and expose retry age/attempt count. An exhausted job becomes a failed/dead-letter item for an operator; a queue retry counter is not evidence of bank failure. A corrected obligation or authorized refund is a distinct linked business operation, not a stealth retry.
16. Idempotency
| Delivery | Business reference | Expected financial effect |
|---|---|---|
| First | PAY-100502 | Apply once after validation/confirmation |
| Second | PAY-100502 | Return existing result / wait for original |
| Third | PAY-100502 | No additional debit, allocation or salary |
Persist a unique business key before processing and compare the request payload on key reuse. Apply another unique constraint to the external event/reference and to the document/outbox event. A unique key alone is not enough: the status check and financial mutation must be within the same transaction.
Callback authentication and idempotency solve different problems. Verify signatures/merchant context first; an attacker-controlled reference does not become trusted just because it is unique. Lock the request row before applying its result.
17. Queue / Background Processing
Durable background work
- Financial transaction inserts outbox event
- COMMIT
- Dispatcher reads unpublished events
- Queue accepts event
- Idempotent worker executes
- Mark completed / retry with same event key
| event_key | aggregate_reference | event_type | published_at |
|---|---|---|---|
| PAY-100502:document | PAY-100502 | GENERATE_DOCUMENT | NULL until dispatched |
Laravel afterCommit() prevents a worker from reading an uncommitted row, but a process can still crash between database commit and sending to a separate queue. A transactional outbox closes that publication gap; consumers must still handle redelivery.
Separate payment, document, notification and reconciliation queues allow independent retries and limits. Payroll/corporate schedulers paginate or chunk work rather than loading all 10,000 payments into one transaction. Do not submit external payments again just because their notification jobs failed.
Laravel dispatch after commit (illustrative job class)
GenerateFeeReceipt::dispatch($payment->id)->afterCommit();
// Job class is illustrative. Use a durable outbox for reliable publication.
// Deduplicate by the saved payment/request/document identity.
18. Receipt / Document Generation
REC-2026-000502 · Student STU1001 · Invoice INV-2026-5001 · Payment PAY-100502 · Amount ₹50,000 · 28 Sep 2026 · Payment SUCCESS / Invoice PAID. The earlier REC-2026-000501 remains ₹30,000. Two payment receipts total ₹80,000; do not issue a misleading ₹80,000 receipt for the ₹50,000 installment.
| Document field | Stored value |
|---|---|
| Receipt No | REC-2026-000502 |
| Student | STU1001 / Rahul Sharma |
| Invoice | INV-2026-5001 |
| Payment | PAY-100502 |
| Amount received | INR 50000.00 |
| Previous installment | INR 30000.00 (receipt 501) |
| Date | 28 Sep 2026 |
| Payment / invoice | SUCCESS / PAID |
Private document lifecycle
- Confirmed SUCCESS
- Database COMMIT
- Pending document / outbox
- Queue PDF renderer
- Private storage
- GENERATED
- Authorized download
| Payment | Document | Action |
|---|---|---|
| SUCCESS | PENDING | Wait for document worker |
| SUCCESS | FAILED_GENERATION | Retry renderer with same document key |
| SUCCESS | GENERATED | Reuse existing file; authorize each download |
Render from the committed immutable amount/reference and approved payroll snapshot, not client input. Reserve a unique receipt/slip number and link one document to one payment. A failed write to private storage cannot turn the already-confirmed financial payment into FAILED.
19. Reconciliation
Illustrative daily totals: internal SUCCESS 4,980, gateway SUCCESS 4,981, bank settlement entries 4,981. Counts alone only flag a discrepancy. Join by provider/payment reference, INR amount, settlement date and fees to locate the missing allocation, verify its authenticity, then apply it once. Settlement lag and net-of-fee values must be compared under a defined policy.
Three-way evidence check
- Internal request / ledger / allocation
- Compare provider confirmation by reference
- Compare bank settlement by date/currency/net policy
- Create discrepancy record
- Investigate with evidence
- Apply idempotent authorized correction
- Close exception with audit
| reference | internal before | evidence | status / resolution |
|---|---|---|---|
| PAY-100502 | UNKNOWN / missing confirmation | Verified provider/bank success | Resolved only after matching identity and amount |
Investigate outcomes, never blindly overwrite
-- Grouping is a monitoring signal; investigate individual references.
SELECT status, COUNT(*) AS rows_found, SUM(amount) AS amount_total
FROM payments
GROUP BY status;
Count mismatches are clues, not sufficient proof. Match identifiers, amounts, currency, beneficiary and dates. Handle settlement lag, fees and refunds explicitly; never change thousands of rows to SUCCESS merely to make dashboard totals agree.
20. Audit Log
| actor | action | entity | old_status | new_status | created_at |
|---|---|---|---|---|---|
| GATEWAY-WEBHOOK | REQUEST_SAVED | PAY-100502 | NULL | PENDING | 2026-09-28 09:00:00 |
| VERIFIED-CALLBACK | RESULT_APPLIED | PAY-100502 | PENDING | SUCCESS | 2026-09-28 12:00:00 |
| DOCUMENT-WORKER | DOCUMENT_GENERATED | PAY-100502 | PENDING | GENERATED | 2026-09-28 12:01:00 |
Each financial status change appends an audit event inside the same local transaction. Metadata includes the request ID, correlation ID, provider evidence reference and reason, with secrets and full beneficiary details removed.
Restrict update/delete permissions on audit history and define retention. A manual reconciliation resolution records the authorized operator, evidence and correction reference. Audit explains who changed a value; the ledger explains the financial entries.
21. Final Database State
These tables describe the completed illustrative main scenario. Independent failure/overpayment exercises above do not silently alter these rows. Batch counts below are derived reporting values where marked.
| payment_reference | amount | status |
|---|---|---|
| PAY-100501 | 30000.00 | SUCCESS |
| PAY-100502 | 50000.00 | SUCCESS |
| id | net_amount | paid_amount | balance_amount | status |
|---|---|---|---|---|
| 5001 | 80000.00 | 80000.00 | 0.00 | PAID |
| receipt_no | payment_id | amount | status |
|---|---|---|---|
| REC-2026-000501 | 100501 | 30000.00 | GENERATED |
| REC-2026-000502 | 100502 | 50000.00 | GENERATED |
| Financial result | Document | Outbox |
|---|---|---|
| SUCCESS | GENERATED after independent job | Published; worker deduplicates redelivery |
22. Interview Questions
Why not mark a browser-closed payment FAILED?
The browser is not the gateway's final record; a verified callback/status query can confirm an already-completed charge.
What happens if ₹90,000 arrives for an ₹80,000 invoice?
Record the full confirmed ₹90,000; allocate only the authorized ₹80,000 and track the ₹10,000 excess as an exception, credit or refund. Never silently discard it.
Why SELECT FOR UPDATE?
Protect a mutable row while the transaction makes and applies a decision from its current value.
What does a waiting request read?
The new committed value after obtaining its lock, not a cached value from before waiting.
Why cannot local rollback reverse a bank payment?
The bank is outside the local transaction boundary; use verified reconciliation and a separate authorized reversal/refund.
How are duplicate webhooks prevented from repeating money effects?
Authenticate the event, persist unique provider/business keys, lock the saved payment and apply the final result once.
What distinguishes FAILED, PENDING and UNKNOWN?
Confirmed rejection; confirmed work in progress; and unresolved external outcome, respectively.
How do 5,000 student payments or 10,000 salaries scale?
Persist independent obligations, use controlled idempotent workers, avoid long global locks, and reconcile each result.
Why queue receipt generation?
Document availability can retry independently without changing a confirmed financial outcome.
What should a deadlock retry repeat?
The entire rolled-back local transaction with its original business identity; never an uncertain external payment.
23. Related SQL Concepts
Connect the sample to ACID, row locks, isolation levels, foreign keys, UNIQUE constraints, conditional UPDATE, SUM/GROUP BY, joins, NULL external references and state transitions. Use window functions to review ordered attempts while preserving each payment's business identity.
