Data Modeling Quiz
Last Updated: 2026-12-01 Status: Complete
Test your judgment on entity design and payment state machines. Answers are collapsed; try each question first.
Question 1: One merchant table
A teammate proposes one merchants table with a single bank account number column. What breaks, and what do you build instead?
View answer
Sub-merchants need several bank accounts: a payout destination, a debit account for recovering negative balances, and replacements over time. One column cannot hold history, verification status or one default per currency, and a raw number would put sensitive data in an ordinary table. Build a bank_account table linked to the sub-merchant with purpose, currency, verification status, effective dates, a token reference to the encrypted number and a last-four display field. Add a partial unique index for one default payout per currency. See Payment Platform Data Model.
Question 2: Hierarchy shortcuts
Your product manager asks to skip the location and terminal levels because "we only sell online." Is that safe?
View answer
Not without a plan. Locations carry descriptors, tax settings and per-store reporting, and terminals matter once card-present arrives. Dropping them entirely means a later migration of every payment row. A cheap compromise is a nullable location_id on payments and a default location per sub-merchant, so online-only merchants have one implicit location and the schema is ready. Keep pricing, settlement and risk at sub-merchant level either way. See Payment Platform Data Model.
Question 3: Intent versus attempt
A customer's first card is declined and they pay with a second card. Is that two payments?
View answer
It is one payment intent with two attempts. The intent holds the merchant's purpose and amount and is the object the caller's idempotency key is tied to; each attempt records one try with a payment method and its own authorization outcome. This keeps reporting honest (one sale, two tries), prevents duplicate orders, and lets decline analysis work per attempt. After the decline the intent goes to requires_payment_method, and the next attempt returns it to authorizing; the declined attempt itself stays terminal. Only a successful attempt produces an authorization that can be captured. See Payment Platform Data Model.
Question 4: Partial captures and refunds
An order is authorized for 10,000 minor units, captured in two parts, and 2,500 is then refunded. How do you model it, and how do you stop over-refunding?
View answer
Create one intent, one attempt and authorization, two capture rows and one refund row linked to a capture. Derive totals by summing child rows rather than storing editable totals. Insert each refund in a transaction that locks the capture row and checks that refunds on that capture stay within its amount; otherwise two concurrent refunds both pass a naive check. Give each refund a request key (unique per capture) that retries resend. Status becomes partially_refunded as a summary of those rows. See Payment Platform Data Model.
Question 5: Settlement lines with no match
A processor settlement file has lines that match no capture. Do you reject the file?
View answer
No. An unmatched line is data, not a parse error. Store every line as a settlement record with a nullable capture reference, then match by the strongest identifiers you saved (processor reference, RRN, network transaction ID, ARN), falling back to composite keys and flagging ambiguity for review. This only works if you stored every identifier on the authorization and capture at the time you received it. Matching rules and break handling are in Reconciliation; the model side is in Payment Platform Data Model.
Question 6: Late webhook
A webhook saying captured arrives after you already recorded the payment as refunded. What should happen?
View answer
Deduplicate by external event ID, then compare the event with current state. Applying captured after refunded would move the lifecycle backwards, so do not apply it. Record it in the history as ignored (stale) so the audit trail shows it arrived, and if it contradicts your records, fetch the current object from the processor and reconcile to that. Because aggregate status can be derived from capture and refund rows, a stale event delays the summary but cannot corrupt the facts. See Payment State Machines.
Question 7: Concurrent captures
Two workers try to capture the same authorized payment at the same moment. How do you make sure one wins?
View answer
Apply the transition inside DataSource.transaction with a conditional update (WHERE status = :from) or a version column, and check that exactly one row was affected. The history row and outbox event are written in the same transaction, so a lost race creates neither. That protects the status, not the amounts: a loser that re-reads and tries again could capture twice. Give each capture request a key with UNIQUE (intent_id, request_key), have retries resend the same key, and guard that cumulative captures do not exceed the authorized amount. See Payment State Machines.
Question 8: Timed-out authorization
An authorization request times out. A developer sets the payment to declined so the customer can retry. What is the risk?
View answer
Nobody knows whether the issuer approved. Marking it declined and starting a new attempt can double-hold or double-charge the customer. Use an explicit unknown attempt state. Against an ISO 8583 host there is no status inquiry, so resolve with a reversal (0400); a status query exists only where the processor or gateway API offers one. Retry an unconfirmed reversal to a limit, escalate, and only then allow a new attempt. Add a job that owns every unknown payment and alerts when it stays unresolved. See Payment State Machines and Idempotency in Payments.
Question 9: Hardcoded dispute deadline
An engineer hardcodes a fixed number of days for the dispute response deadline. Why is that a bug, and what do you store?
View answer
Deadlines vary by network, reason code and stage, and they change when pre-arbitration or arbitration starts. Store due_by on each dispute, taken from the processor or network notification, and refresh it whenever the stage changes. Use it in the guard for submitting evidence and to drive reminders. Also keep the financial impact separate: a provisional debit when the chargeback arrives and a reversal if it is won. See Payment State Machines and Chargeback Lifecycle.
Question 10: Paid is not final
A payout shows paid and two days later the bank returns it. Your state machine has paid as terminal. What is wrong?
View answer
For ACH, a return can arrive after a payout looked successful. Add returned, reachable from paid, matched by trace reference. The transition re-credits the merchant's balance, blocks the destination and pauses payouts. A returned payout is not a negative balance; recovery applies only if that balance has since been spent. Document this as an explicit exception to the terminal-state rule and cover it in the transition-matrix test. See Payment State Machines and Payouts.
Related Topics
- Payment Platform Data Model — entities, DDL and multi-tenancy
- Payment State Machines — transition tables and enforcement code
- Reconciliation — matching settlement lines to captures