Corporate Salary: 10,000 Employees
A corporate submits ₹75 crore for 10,000 employees. Follow maker/checker approval, individual bank outcomes and an unresolved timeout through reconciliation.
Illustrative production scenario — fictional educational records
1. Business Scenario
A fictional corporation owes 10,000 employees an average ₹75,000: 10,000 × 75,000 = ₹750,000,000 = ₹75 crore. The batch is an operational grouping of independent payment obligations, not a single all-or-nothing bank transaction.
The bank reports 9,970 SUCCESS, 20 FAILED and 10 PENDING/UNKNOWN. This lesson displays status PARTIALLY_COMPLETED with processing_status PROCESSING and is_final = false. The label reports progress, not finality: all ten unresolved items remain visible.
The eventual illustrated outcome is 9,980 successes and 20 confirmed failures. Only then processing_status becomes CLOSED and is_final=true. Bank balance shown in a local cache is not an authority to spend without the bank's balance/reservation controls.
| Reference | Amount per main request | Scope |
|---|---|---|
| SAL-2026-09-EMP005 | ₹75,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.
corporate_accounts
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| company_id | BIGINT |
| bank_account_id | BIGINT FK protected bank account |
| status | VARCHAR(20) |
| available_balance | DECIMAL(19,2) |
| balance_as_of | TIMESTAMP |
₹80 crore is an illustrative bank-reported snapshot. Bank reservations and fees affect actual available cash.
salary_batches
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| company_id | BIGINT |
| batch_reference | VARCHAR(100) UNIQUE |
| salary_month | CHAR(7) |
| employee_count | INT |
| total_amount | DECIMAL(19,2) |
| status | VARCHAR(30) |
| processing_status | VARCHAR(20) |
| is_final | BOOLEAN |
| created_by | BIGINT |
| approved_by | BIGINT NULL |
| created_at | TIMESTAMP |
| approved_at | TIMESTAMP NULL |
| submitted_at | TIMESTAMP NULL |
created_by 11 != approved_by 22. A valid permission check is required in addition to different IDs.
salary_batch_items
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| salary_batch_id | BIGINT FK |
| employee_id | BIGINT |
| beneficiary_account | VARCHAR(100) encrypted/tokenized |
| amount | DECIMAL(19,2) |
| bank_code | VARCHAR(30) |
| status | VARCHAR(30) |
| payment_reference | VARCHAR(100) UNIQUE |
| failure_code | VARCHAR(100) NULL |
Beneficiaries and bank codes are deliberately non-routable example tokens. Validate actual identifiers using the bank's supported scheme.
bank_payment_requests
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| batch_item_id | BIGINT UNIQUE FK |
| business_reference | VARCHAR(100) UNIQUE |
| amount | DECIMAL(19,2) |
| status | VARCHAR(30) |
| attempt_count | INT |
| external_reference | VARCHAR(100) NULL |
The same business reference remains on every investigation or safe retry.
bank_responses
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| request_id | BIGINT FK |
| provider_event_id | VARCHAR(100) UNIQUE |
| bank_reference | VARCHAR(100) |
| status | VARCHAR(30) |
| amount | DECIMAL(19,2) |
| received_at | TIMESTAMP |
Append verified responses; prevent duplicate event application. A response is evidence, not permission to double-pay.
reconciliation_records
| Column | Type / constraint |
|---|---|
| id | BIGINT PK |
| payment_reference | VARCHAR(100) |
| internal_status | VARCHAR(30) |
| external_status | VARCHAR(30) |
| amount | DECIMAL(19,2) |
| status | VARCHAR(30) |
| resolution | VARCHAR(255) NULL |
Resolve only after matching company, beneficiary, amount, currency, date and bank reference.
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 | company_id | bank_account_id | status | available_balance | balance_as_of |
|---|---|---|---|---|---|
| 90 | 44 | 900 | ACTIVE | 800000000.00 | 2026-09-28 08:00:00 |
| id | company_id | batch_reference | salary_month | employee_count | total_amount | status | processing_status | is_final | created_by | approved_by | created_at | approved_at | submitted_at |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 50 | 44 | BATCH-2026-09-44 | 2026-09 | 10000 | 750000000.00 | PARTIALLY_COMPLETED | PROCESSING | false | 11 | 22 | 2026-09-28 08:10:00 | 2026-09-28 08:30:00 | 2026-09-28 09:00:00 |
| id | salary_batch_id | employee_id | beneficiary_account | amount | bank_code | status | payment_reference | failure_code |
|---|---|---|---|---|---|---|---|---|
| 50001 | 50 | 1 | TOKEN-EMP001 | 75000.00 | DEMO-BANK | SUCCESS | SAL-2026-09-EMP001 | NULL |
| 50002 | 50 | 2 | TOKEN-EMP002 | 75000.00 | DEMO-BANK | SUCCESS | SAL-2026-09-EMP002 | NULL |
| 50003 | 50 | 3 | TOKEN-EMP003 | 75000.00 | DEMO-BANK | FAILED | SAL-2026-09-EMP003 | ACCOUNT_CLOSED |
| 50004 | 50 | 4 | TOKEN-EMP004 | 75000.00 | DEMO-BANK | FAILED | SAL-2026-09-EMP004 | INVALID_ACCOUNT |
| 50005 | 50 | 5 | TOKEN-EMP005 | 75000.00 | DEMO-BANK | UNKNOWN | SAL-2026-09-EMP005 | BANK_TIMEOUT |
| 50006 | 50 | 6 | TOKEN-EMP006 | 75000.00 | DEMO-BANK | SUCCESS | SAL-2026-09-EMP006 | NULL |
| id | batch_item_id | business_reference | amount | status | attempt_count | external_reference |
|---|---|---|---|---|---|---|
| 60005 | 50005 | SAL-2026-09-EMP005 | 75000.00 | UNKNOWN | 1 | NULL |
| id | request_id | provider_event_id | bank_reference | status | amount | received_at |
|---|---|---|---|---|---|---|
| 61005 | 60005 | EVT-STATUS-005 | BANK-005 | SUCCESS | 75000.00 | 2026-09-28 12:00:00 |
| id | payment_reference | internal_status | external_status | amount | status | resolution |
|---|---|---|---|---|---|---|
| 62005 | SAL-2026-09-EMP005 | UNKNOWN | SUCCESS | 75000.00 | OPEN | NULL |
| 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
- Corporate payroll freezes amounts
- Maker 11 creates batch
- Validate 10000 items and sum
- Checker 22 approves
- Outbox and payment orchestrator
- Bank-specific adapter
- Independent bank outcomes
- Status query for EMP005
- Reconciliation
- Salary documents
| Field | Value / rule |
|---|---|
| reference | SAL-2026-09-EMP005 |
| amount | ₹75,000; validate against saved request |
| authenticated actor | BANK-STATUS-RECONCILER |
| response | Return saved result on duplicate; show pending while unresolved |
5. What Happens Inside the Application
Validate count, sum, positive amounts, employee eligibility, beneficiary scheme and unique payment references before approval. Reject malformed rows without any financial operation. Bind the maker's payload and version to the checker approval so editing a batch invalidates approval.
The orchestrator claims one saved request, records submission intent, commits, and calls the bank adapter. Only the adapter knows the bank's protocol and authentication. No worker may silently invent SAL-2026-09-EMP005-RETRY-2 after a timeout.
The reconciler verifies response EVT-STATUS-005 against the saved ₹75,000 obligation. It locks request 60005 and item 50005 in the standard order, records BANK-005 and SUCCESS once, resolves exception 62005, and creates document/audit outbox work. Derived batch counts still retain the other nine unresolved items until each is confirmed.
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
- Verified bank query returns BANK-005 SUCCESS
- BEGIN
- Lock request 60005
- Lock item 50005
- Check matching amount/reference and current state
- UNKNOWN → SUCCESS, save bank reference
- Resolve reconciliation 62005; audit/outbox
- COMMIT
- Recompute batch outcome counts
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 * FROM bank_payment_requests WHERE id = 60005 FOR UPDATE;
SELECT id, amount, payment_reference, status FROM salary_batch_items WHERE id = 50005 FOR UPDATE;
-- Apply only a verified matching bank result; an existing SUCCESS is a no-op.
UPDATE bank_payment_requests SET status = 'SUCCESS', external_reference = 'BANK-005' WHERE id = 60005;
UPDATE salary_batch_items SET status = 'SUCCESS', failure_code = NULL WHERE id = 50005;
UPDATE reconciliation_records SET status = 'RESOLVED', resolution = 'Verified BANK-005; no resubmission' WHERE id = 62005;
-- Audit/outbox entry records UNKNOWN -> SUCCESS.
COMMIT;
SELECT status, COUNT(*) AS items, SUM(amount) AS total
FROM salary_batch_items WHERE salary_batch_id = 50 GROUP BY status;
-- Close the parent only when PENDING/UNKNOWN/READY/SUBMITTED/PROCESSING count is zero.
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 | Worker sends EMP005 using saved reference | Bank accepts request |
| T1 | HTTP response times out; record UNKNOWN | Bank may already have paid |
| T2 | Retry worker claims investigation, not payment | Query original reference |
| T3 | Query returns BANK-005 SUCCESS; lock request | Concurrent callback waits on same request |
| T4 | Commit SUCCESS once; resolve exception | Duplicate result becomes a no-op |
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 |
|---|---|
| Batch total | 10000 × 75000 = 750000000 (₹75 crore) |
| Initial successes | 9970 × 75000 = 747750000 |
| Confirmed failures | 20 × 75000 = 1500000 |
| Unresolved amount | 10 × 75000 = 750000 |
| Final successes | 9980 × 75000 = 748500000 |
| Final unpaid failures | 1500000; not rolled back successful cash |
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 |
|---|---|---|
| EMP005 | UNKNOWN / BANK_TIMEOUT | SUCCESS / BANK-005 |
| request 60005 attempts | 1 | 1 (status inquiry is not a second payment) |
| reconciliation 62005 | OPEN | RESOLVED |
| batch 50 pending/unknown count | 10 | 9 after EMP005; 0 after all ten resolutions |
| batch 50 is_final | false | true only after zero unresolved items |
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 |
Batch summary PARTIALLY_COMPLETED is deliberately non-final while processing_status=PROCESSING and is_final=false. Success, failed and unresolved counters remain visible. Close only after all unresolved items reach an evidenced final result.
Corporate parent batch lifecycle
- DRAFT: editable
- VALIDATED: counts and amounts checked
- APPROVED: separate checker authorizes frozen version
- SUBMITTED: no assumed success
- PROCESSING: unresolved items remain
- COMPLETED: all success / PARTIALLY_COMPLETED: inspect finality and counts
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
ACCOUNT_CLOSED, INVALID_ACCOUNT and BENEFICIARY_BLOCKED are confirmed failures only when the bank reports a terminal rejection. BANK_TIMEOUT is UNKNOWN. PENDING means the bank says processing; UNKNOWN means the application does not know. Record each item result and keep unresolved amounts visible.
| 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 |
15. Retry Flow
Do not create SAL-2026-09-EMP005-RETRY-2 merely to get a new request accepted. Query the original reference, await signed callback or compare the bank statement. Retry transmission only when the adapter/provider contract establishes it is safe; preserve the original business key and record each attempt separately.
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 | SAL-2026-09-EMP005 | Apply once after validation/confirmation |
| Second | SAL-2026-09-EMP005 | Return existing result / wait for original |
| Third | SAL-2026-09-EMP005 | 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 |
|---|---|---|---|
| SAL-2026-09-EMP005:document | SAL-2026-09-EMP005 | 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)
GenerateSalaryAdvice::dispatch($batchItem->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
Salary advice for EMP005 includes batch BATCH-2026-09-44, ₹75,000, business reference SAL-2026-09-EMP005 and bank reference BANK-005. Generate after confirmation and commit; restrict download to the employee or authorized payroll staff.
| Document field | Stored value |
|---|---|
| Salary advice | ADVICE-2026-09-EMP005 |
| Batch | BATCH-2026-09-44 |
| Employee | EMP005 |
| Reference | SAL-2026-09-EMP005 |
| Bank reference | BANK-005 |
| Amount paid | INR 75000.00 |
| Status | SUCCESS after reconciliation |
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
Join internal items and the bank report by business reference and bank reference, then verify beneficiary token, amount, currency and date. Initial successes 9970 differ from bank-confirmed 9980; the ten missing confirmations are resolved individually. Compare cash totals with settlement/fees, not just counts. Twenty confirmed failures remain liabilities to investigate.
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 |
|---|---|---|---|
| SAL-2026-09-EMP005 | 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 salary_batch_items
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 |
|---|---|---|---|---|---|
| BANK-STATUS-RECONCILER | REQUEST_SAVED | SAL-2026-09-EMP005 | NULL | UNKNOWN | 2026-09-28 09:00:00 |
| VERIFIED-CALLBACK | RESULT_APPLIED | SAL-2026-09-EMP005 | UNKNOWN | SUCCESS | 2026-09-28 12:00:00 |
| DOCUMENT-WORKER | DOCUMENT_GENERATED | SAL-2026-09-EMP005 | 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.
| id | success | failed | unresolved | status | processing_status | is_final |
|---|---|---|---|---|---|---|
| 50 | 9980 | 20 | 0 | PARTIALLY_COMPLETED | CLOSED | true |
| employee | amount | status | reference |
|---|---|---|---|
| EMP005 | 75000.00 | SUCCESS | SAL-2026-09-EMP005 |
| EMP003 | 75000.00 | FAILED | SAL-2026-09-EMP003 |
| id | status | resolution |
|---|---|---|
| 62005 | RESOLVED | BANK-005 confirmed; no duplicate submission |
| Financial result | Document | Outbox |
|---|---|---|
| SUCCESS | GENERATED after independent job | Published; worker deduplicates redelivery |
22. Interview Questions
Can PARTIALLY_COMPLETED hide ten pending items?
No. In this explicit model the summary coexists with PROCESSING and is_final=false until every item is resolved.
What does the checker approve?
The frozen company/month/count/amount/beneficiary payload version, after independent authorization; not an editable batch that the maker can later change.
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.
