Backend engineer: Transactions and Concurrent State
Original technical interview cases on atomic business invariants, isolation, idempotency, multi-service state transitions, and concurrency verification. Questions state effect boundaries and distinguish database guarantees from external behavior.
These prompts are original practice. They are not questions from a named employer or a live hiring loop.
1.An order operation must create an order and reserve its inventory together. A crash can occur between the writes. Which boundary directly expresses the all-or-neither requirement?
Show answer and explanation
- A response sent before either write
- Two independently acknowledged writes
- A retry counter outside both writes
- An atomic transaction over both writes
Answer: An atomic transaction over both writes
Atomicity prevents exposing a partial commit within the transaction's supported scope. Durability and external effects need their own guarantees.
2.A transaction commits a balance change, but the application loses the commit response. What does the timeout alone establish?
Show answer and explanation
- The transaction definitely rolled back.
- The transaction definitely never started.
- The caller does not know the outcome.
- The committed value must be applied twice.
Answer: The caller does not know the outcome.
A lost response creates an ambiguous outcome. A suitable status query or idempotent retry protocol is needed rather than assuming failure.
3.Two requests read stock=10, each subtracts 3 locally, and both overwrite stock with 7. What value would applying both decrements serially produce?
Show answer and explanation
- 4
- 10
- 7
- 1
Answer: 4
Both decrements total six, so serial application leaves four. The described overwrite loses one update.
4.A database supports atomic UPDATE stock=stock−3 with a predicate stock>=3. Why can this be safer than an unprotected read-then-write?
Show answer and explanation
- It removes the need to check affected-row count.
- It makes every business invariant globally serializable.
- The condition and state change can be evaluated together.
- It guarantees the caller always receives the commit response.
Answer: The condition and state change can be evaluated together.
A conditional atomic change can avoid a race between checking and modifying that row. The application must still interpret success and handle wider invariants.
5.An optimistic update succeeds only if stored revision=12, then changes it to 13. Another writer has already stored revision 13. What should the conditional update report?
Show answer and explanation
- An automatic safe overwrite
- A guarantee the other writer made the same business change
- Success because the new value is also 13
- A conflict with no matching revision
Answer: A conflict with no matching revision
Revision comparison checks whether the expected state is still current. A mismatched revision is not permission to overwrite newer work.
6.A client retries a create request after losing its response. Which identifier can help recognize the same intended operation?
Show answer and explanation
- A new random operation key on every retry
- A stable operation key across retries
- Only the server's current thread number
- Only the latest network connection ID
Answer: A stable operation key across retries
Idempotency depends on recognizing logical identity. Changing the operation key on each attempt defeats that recognition.
7.An idempotency record maps a key to one request body and result. A later request reuses the key with a materially different body. What should the API contract specify?
Show answer and explanation
- Always reexecute the new body without checking
- Always pretend the new body equals the old one
- A guarantee identical keys imply identical payloads
- A conflict or other explicit mismatch policy
Answer: A conflict or other explicit mismatch policy
Key reuse must not silently conflate different operations. Compare a suitable request identity and apply the documented mismatch policy.
8.An idempotent handler stores its deduplication marker before performing the business write, in separate non-atomic steps. It crashes between them. What risk appears?
Show answer and explanation
- A later retry can be suppressed although the effect is missing.
- The marker guarantees every downstream effect exists.
- The effect must have been completed twice.
- The crash changes the request body's meaning.
Answer: A later retry can be suppressed although the effect is missing.
Marker and effect coordination matters. An early marker can turn an incomplete operation into an apparent duplicate.
9.A handler performs the effect first and stores its deduplication marker afterward, without atomic coordination. It crashes between those steps. What can a retry do?
Show answer and explanation
- Guarantee exactly one effect
- Prove the first effect rolled back
- Recover the marker from the response automatically
- Apply the effect again
Answer: Apply the effect again
A missing marker does not mean a missing effect. Use a suitable atomic or recoverable protocol for the actual effect boundary.
10.A database transaction writes a business row and an outbox row atomically. What problem does the outbox chiefly address?
Show answer and explanation
- Removing all need for consumer deduplication
- Recording the intent to publish with the business commit
- Making every external consumer exactly-once automatically
- Guaranteeing immediate network delivery
Answer: Recording the intent to publish with the business commit
An outbox closes a database-write versus publication-intent gap. Delivery and downstream effects still need their own protocols.
11.An outbox dispatcher sends a message and crashes before marking it sent. What should a receiver generally be prepared to handle?
Show answer and explanation
- Only messages in reverse chronological order
- A repeated delivery
- A guaranteed missing business row
- A proof that the first send never reached the receiver
Answer: A repeated delivery
The dispatcher may send again after restart. A durable business identity and suitable receiver behavior can make duplicates safe.
12.Two independent handlers both see no existing row for an operation key, then attempt to insert it. What database mechanism can arbitrate that race?
Show answer and explanation
- Only a longer retry delay
- Only a process-local flag on one handler
- A unique constraint on the operation key
- Only a prior existence query
Answer: A unique constraint on the operation key
An unprotected check is not atomic with a later insert. The database constraint enforces uniqueness across competing writers.
13.A process-local mutex protects a handler running on one server. The service scales to five separate processes. What must be reassessed?
Show answer and explanation
- A guarantee local locking now covers all servers
- Coordination across process boundaries
- Only the number of requests in one process
- Only the mutex variable's spelling
Answer: Coordination across process boundaries
A local mutex does not automatically coordinate other processes. Put the invariant at a boundary that covers every relevant writer.
14.A multi-row transfer subtracts 20 from account A and adds 20 to B in one atomic transaction. What is the intended change in A+B, ignoring fees?
Show answer and explanation
- 20
- 40
- −20
- 0
Answer: 0
The debit and credit cancel in the total. This is a useful invariant, distinct from whether each individual balance change is correct.
15.A transaction correctly preserves total balance but swaps the destination account with another account. What does the total alone fail to verify?
Show answer and explanation
- The unchanged aggregate total
- The arithmetic sum of the tested balances
- Correct routing of the transfer
- The existence of both recorded account changes
Answer: Correct routing of the transfer
An invariant can hold while the business operation is wrong. Verify relevant identities and account-level effects as well as totals.
16.An API sends success before the transaction commits. The commit later fails. What contract problem can result?
Show answer and explanation
- Acknowledgment of an effect that was not committed
- Automatic completion by the HTTP client
- Only a slower successful response
- A guaranteed duplicate commit
Answer: Acknowledgment of an effect that was not committed
A success response should match the promised completion boundary. If success means committed state, respond after that boundary is known to have succeeded.
17.A client needs durable acceptance rather than immediate completion of a long job. What should an accepted response identify?
Show answer and explanation
- An assumption all work is already finished
- Only the worker's transient memory address
- A guarantee the job can no longer fail
- A durable job identity and status contract
Answer: A durable job identity and status contract
Acceptance and completion are different states. A durable job record and clear status transitions let the caller track the promised work.
18.A booking service checks availability on a lagging replica, then inserts on the primary without an enforcing constraint. What remains possible?
Show answer and explanation
- Conflicting bookings can both be accepted.
- A successful read reserves the resource.
- Replication lag can only affect printed timestamps.
- Replica reads guarantee current primary availability.
Answer: Conflicting bookings can both be accepted.
A stale read is not a reservation. Enforce the intended concurrency invariant at the write boundary or through another justified coordination mechanism.
19.A read-your-writes requirement follows a successful update, but the next read is routed to a lagging replica. What can the client observe?
Show answer and explanation
- Only an error rather than any stale data
- Its previous value
- The primary's current state by definition
- A guarantee of its new value
Answer: Its previous value
Replica lag can violate that session expectation. Use a routing, token, or consistency mechanism that supports the promised semantics.
20.A transaction retries after a serialization failure. Which unit normally needs to be reconsidered under the new snapshot?
Show answer and explanation
- The full transactional decision
- Only the response formatting
- Only the final arithmetic assignment
- A guarantee old reads remain valid after retry
Answer: The full transactional decision
A retry can observe different state. Reexecute the relevant reads and decisions rather than reuse stale assumptions from the aborted attempt.
21.Two on-call engineers are each allowed to go off duty only if another remains. Under snapshot isolation, each transaction sees both on duty and updates only its own row. What anomaly can violate the joint rule?
Show answer and explanation
- A dirty read necessarily
- A duplicate primary key necessarily
- Write skew
- A guaranteed lost update on one shared row
Answer: Write skew
Separate-row writes can each be consistent with their own snapshot while jointly violating a cross-row invariant.
22.A transaction reads only committed data, then rereads a row after another transaction commits an update. The two values differ. What phenomenon is described?
Show answer and explanation
- A guaranteed corrupt disk page
- A dirty read
- An atomicity violation by definition
- A nonrepeatable read
Answer: A nonrepeatable read
The earlier read was committed, but the transaction's view changed. Isolation guarantees determine whether that is permitted.
23.A range query returns five matching rows. A later execution in the same transaction returns six after a concurrent insertion. What phenomenon is illustrated?
Show answer and explanation
- A phantom read
- A duplicate column name
- A dirty write necessarily
- An exact repeatable snapshot
Answer: A phantom read
The matching set changed because another transaction added a qualifying row. Range-query behavior matters beyond locking existing individual rows.
24.A transaction reads a value written by another transaction that has not committed. What is that called?
Show answer and explanation
- A serialization retry
- A dirty read
- A durable acknowledgment
- A repeatable committed read
Answer: A dirty read
The observation includes uncommitted state, which could later be rolled back. This is distinct from rereading a newly committed value.
25.A system promises serializable committed transactions. What outcome property is promised for those transactions?
Show answer and explanation
- No transaction can ever abort
- The same wall-clock completion order as request arrival
- Equivalence to some serial execution
- All reads must be served from a replica
Answer: Equivalence to some serial execution
Serializability concerns the effect of concurrent transactions. It does not require arrival-order execution or guarantee every attempt commits.
26.A serializable database rejects one transaction to prevent an anomaly. What should an application be designed to do when appropriate?
Show answer and explanation
- Treat every such rejection as data corruption.
- Retry the transaction under a bounded policy.
- Retry only the network response with no database work.
- Return success without a commit.
Answer: Retry the transaction under a bounded policy.
Aborts can be part of enforcing the isolation guarantee. A correct application handles retryable failures with suitable bounds and operation semantics.
27.A database snapshot gives a consistent view of committed rows, but an external service response changes during the transaction. What is outside that snapshot's automatic scope?
Show answer and explanation
- The database rows included in the snapshot
- The external service's state
- The transaction's own visible writes under its contract
- The snapshot's selected database version
Answer: The external service's state
A database isolation guarantee does not automatically encompass arbitrary external observations. Define how those inputs participate in the decision.
28.A transaction reads a cached price whose version is unrelated to the database snapshot, then writes an invoice. What should correctness analysis include?
Show answer and explanation
- Consistency of the price used with the invoice contract
- Only whether the cache lookup succeeded
- A guarantee any cache value is part of the same snapshot
- Only the transaction's SQL isolation level
Answer: Consistency of the price used with the invoice contract
Transactional database reads do not automatically validate a separate cache's semantics, version, or freshness.
29.A request performs two database transactions, with a network call between them. Can the application assume they form one atomic unit by using the same request ID?
Show answer and explanation
- Yes; all work in one request is automatically atomic.
- No; atomicity is impossible for any database work.
- Yes; a common ID forces shared rollback.
- No; request identity alone supplies no such boundary.
Answer: No; request identity alone supplies no such boundary.
Logical request grouping is not an atomic commit protocol. Describe the actual transaction and compensation boundaries.
30.A compensation reverses a previously completed external action. Why is this different from a database rollback?
Show answer and explanation
- A compensation always erases every external observation.
- A rollback always requires a second business action.
- The original action may already have been observed.
- A compensation is guaranteed never to fail.
Answer: The original action may already have been observed.
Compensation is a new action with its own failures and semantics. It need not restore the world as if the original action had never occurred.
31.A saga reserves stock, charges payment, then fails to arrange delivery. What should its failure design state?
Show answer and explanation
- Which compensations or alternative outcomes are valid
- Only the order of successful HTTP responses
- Only a longer timeout for the final step
- A guarantee every service shares one database rollback
Answer: Which compensations or alternative outcomes are valid
A multi-service workflow needs explicit recovery semantics for partial progress. The correct compensation depends on the actual business action.
32.A reservation expires at 12:00. A payment response arrives at 12:01. What must the workflow coordinate?
Show answer and explanation
- Whether the reservation is still valid for completion
- Only the payment request's original start time
- A guarantee a past reservation remains active
- Only the response's successful status code
Answer: Whether the reservation is still valid for completion
Delayed success can arrive after prerequisites expire. Define state transitions and race handling rather than infer validity from a successful response alone.
33.An API performs a conditional transition from pending to confirmed. Two workers try to confirm the same pending record. What result should a suitable atomic transition expose?
Show answer and explanation
- Two independent pending states for one record
- A guarantee neither worker can proceed
- Only a shared response timestamp
- At most one matching state change
Answer: At most one matching state change
A compare-and-change predicate can let one writer advance the state while the other observes no matching pending row. Wider effects must respect that outcome.
34.A transaction checks a token's expiry using one time value, then commits much later. What should the authorization contract define?
Show answer and explanation
- A guarantee validity at request arrival covers every later action
- Only the timestamp's display format
- The time at which validity must hold
- Only the number of database statements
Answer: The time at which validity must hold
Expiry-sensitive decisions need a clear temporal boundary. An earlier check may not satisfy a requirement that validity hold at effect time.
35.A transaction holds a row lock while waiting 30 seconds for an external network response. What operational consequence should design review consider?
Show answer and explanation
- Longer contention and occupied transaction resources
- Elimination of all conflicting requests
- Automatic rollback of the network action on timeout
- A guarantee the external service joins the database transaction
Answer: Longer contention and occupied transaction resources
Keeping locks and transactions open across slow external work can increase contention and failure coupling. It does not extend atomicity to that service.
36.Two transactions acquire locks in opposite order: one holds X and waits for Y, while the other holds Y and waits for X. What situation is present?
Show answer and explanation
- A successful serial execution
- A dirty read necessarily
- A deadlock cycle
- A guarantee both transactions have committed
Answer: A deadlock cycle
The wait-for cycle prevents progress without intervention. Consistent lock ordering can reduce this risk, and applications still need appropriate failure handling.
37.A database aborts a transaction as a deadlock victim. The application retries only its last statement, assuming earlier statements remain committed. What should be checked?
Show answer and explanation
- A guarantee every statement commits independently
- Only the retry delay
- The actual rollback scope
- Only the connection's display name
Answer: The actual rollback scope
An aborted transaction may have rolled back its earlier work. Retry behavior must match the database's actual transaction and savepoint semantics.
38.An inventory update reserves two units only when available>=2. It affects zero rows. What must the caller avoid assuming?
Show answer and explanation
- That no matching update occurred
- That the requested row may no longer be eligible
- That it should examine the condition or identity
- That the reservation succeeded
Answer: That the reservation succeeded
Zero affected rows can mean the condition did not hold or the target did not match. Treat the actual outcome according to the API contract.
39.A cross-row invariant requires total reserved capacity≤100. Each transaction updates a different reservation row after reading total=90. Both add 8. What total can result without adequate coordination?
Show answer and explanation
- 90
- 98
- 106
- 100
Answer: 106
Each sees room for eight independently, but the combined increase is sixteen. A row-local update can miss the shared capacity constraint.
40.An event consumer receives state versions 8, 10, then 9 for one entity. The contract says retain the greatest version. What final version should be stored?
Show answer and explanation
- 27
- 10
- 8
- 9
Answer: 10
Arrival order is not version order. A suitable conditional update prevents the late version nine from replacing version ten.
41.Operation A completes before operation B begins. A linearizable object must order their effects how?
Show answer and explanation
- B before A always
- A before B
- Either order regardless of real time
- Only by the alphabetic order of operation IDs
Answer: A before B
Linearizability respects real-time precedence for nonoverlapping operations. Concurrent operations may admit more than one valid order.
42.A transaction system is serializable. A new requirement says that if T1 completes before T2 starts, T1 must precede T2 in the equivalent serial order. Which stronger guarantee is being requested?
Show answer and explanation
- Read committed isolation
- Only row-level atomicity
- Strict serializability
- Best-effort asynchronous replication
Answer: Strict serializability
Strict serializability combines serializability with the stated real-time precedence requirement. Serializability alone does not impose that external ordering.
43.A database check reads a row and releases its lock before a later dependent write. Another writer changes the row between those steps. What gap remains?
Show answer and explanation
- The check and effect are not protected together.
- The second writer must have used an invalid key.
- The first lock guarantees every later operation sees the old state.
- Only a display-order difference is possible.
Answer: The check and effect are not protected together.
Protection must span the decision and effect or be replaced with a suitable atomic condition or version check.
44.An advisory lock is effective only when writers voluntarily acquire it. One write path bypasses it. What does the lock fail to enforce globally?
Show answer and explanation
- The existence of an advisory key
- The intended mutual exclusion
- The ability to inspect the bypassing path
- The fact that cooperating writers can acquire it
Answer: The intended mutual exclusion
Cooperative locking cannot coordinate a writer that ignores the protocol. Cover all relevant paths or enforce the invariant at another suitable boundary.
45.Two unrelated customer IDs map to the same lock stripe. The protected operation is otherwise correct. What is the usual direct cost?
Show answer and explanation
- Unnecessary serialization between those customers
- Guaranteed lost updates
- A proof that the lock is never acquired
- Automatic corruption of both IDs
Answer: Unnecessary serialization between those customers
A collision can reduce concurrency without necessarily breaking correctness. Distinguish lock granularity costs from missing protection.
46.A service adopts a total ordering for acquiring multiple resource locks. What risk does this primarily reduce when all relevant paths comply?
Show answer and explanation
- Cyclic lock waits
- Every transaction abort for every reason
- All contention on a popular resource
- Every possible slow request
Answer: Cyclic lock waits
Consistent acquisition order helps prevent circular wait. It does not remove ordinary contention or every failure mode.
47.A booking rule prohibits overlapping intervals for the same room. Checking only whether the proposed booking ID is unique establishes what?
Show answer and explanation
- Nonoverlap of every time interval
- A guarantee no concurrent booking exists
- Only ID uniqueness, not nonoverlap
- Correct room capacity automatically
Answer: Only ID uniqueness, not nonoverlap
The key constraint and temporal exclusion rule protect different invariants. Enforce the actual resource-and-time relationship.
48.A supplied unique-key contract treats NULL values as distinct. Several rows have NULL
operation_key. What does the constraint alone permit?Show answer and explanation
- Multiple such null keys
- No null keys
- Only null keys and no nonnull keys
- Exactly one null key
Answer: Multiple such null keys
Under the stated semantics, nulls do not collide for uniqueness. Add the required missingness constraint if every operation needs an identity.
49.A cache says five seats remain, but reservations on the authoritative store have already consumed them. What should allocate a seat safely?
Show answer and explanation
- A guarantee the cached count reserves capacity
- An enforcing authoritative reservation operation
- Only decrementing the local cached number
- Only refreshing the client display after success
Answer: An enforcing authoritative reservation operation
A cache can guide presentation or reduce reads, but a stale availability number is not an allocation guarantee.
50.A transaction inserts a child row before its parent, and a supplied database supports a foreign key deferred until commit. What must still be true at successful commit?
Show answer and explanation
- The relationship may remain broken indefinitely.
- Deferral removes the constraint entirely.
- The required parent relationship holds.
- The parent must have been inserted before every child statement.
Answer: The required parent relationship holds.
Deferral changes when the constraint is checked, not the final relationship it requires. The exact semantics depend on the configured database contract.
51.Worker A's lease expires, and worker B acquires a newer lease. A later resumes and attempts a write. What mechanism can reject stale ownership at the write boundary?
Show answer and explanation
- Only the fact A once held a lease
- Only a longer lease-renewal log
- A checked fencing token
- A guarantee expired workers cannot execute code
Answer: A checked fencing token
A monotonically ordered ownership token can let the target reject writes from an obsolete lease. Merely recording expiry does not stop a paused process from resuming.
52.A value changes from A to B and back to A. A compare-and-swap checks only the value A. What can it miss?
Show answer and explanation
- The current value being A
- The existence of a successful equality test
- The ability to compare the current bits
- An intervening state change
Answer: An intervening state change
The ABA pattern can hide intervening changes. A suitable version or other protocol can distinguish histories when that distinction matters.
53.A database allocates sequence IDs before transactions commit. One transaction aborts. What may legitimately appear in committed IDs?
Show answer and explanation
- A proof of a missing committed record
- A guarantee of contiguous IDs
- A required duplicate of the aborted ID
- A gap
Answer: A gap
Allocation and commit are separate. Gaps do not by themselves establish loss of committed business data.
54.T1 obtains sequence ID 100, pauses, and commits after T2 obtains ID 101 and commits. Which conclusion does this example demonstrate?
Show answer and explanation
- A higher sequence ID must always commit later.
- Both transactions must have committed simultaneously.
- The smaller ID must belong to an aborted transaction.
- Allocation order can differ from commit order.
Answer: Allocation order can differ from commit order.
The lower ID was allocated first but committed later in the supplied history. Record ordering evidence with the semantics the application actually needs.
55.Two servers use wall-clock timestamps as conflict versions, but their clocks can skew. What needs justification?
Show answer and explanation
- A guarantee a later numeric clock value always means a newer business update
- Only the number of timestamp digits
- Only whether timestamps parse successfully
- Whether timestamp order represents the intended state order
Answer: Whether timestamp order represents the intended state order
Clock values are not automatically reliable logical versions across skewed writers. Choose a versioning or coordination design suited to the invariant.
56.A batch API allows item-level commits rather than all-or-nothing behavior. Three of five items succeed. What should the response make clear?
Show answer and explanation
- That the entire batch necessarily rolled back
- Each item's actual outcome
- Only one success flag with no scope definition
- That all five succeeded because some work committed
Answer: Each item's actual outcome
Partial-success semantics need explicit identities and statuses. Callers must know what to retry without repeating completed effects incorrectly.
57.A business invariant spans two shards, but transactions are atomic only within one shard. What does sharding alone fail to supply?
Show answer and explanation
- An atomic boundary across both shards
- The existence of local transactions
- The possibility of defining a cross-shard protocol
- The ability to route a record by shard key
Answer: An atomic boundary across both shards
A partition layout does not create a distributed transaction guarantee. Repartitioning, coordination, or suitable workflow semantics may be needed.
58.A distributed commit protocol can leave participants waiting while its coordinator is unavailable. What tradeoff should be assessed?
Show answer and explanation
- A guarantee coordination has no failure costs
- Availability and recovery behavior during uncertainty
- A proof that all prepared work already committed
- Only the coordinator's normal response size
Answer: Availability and recovery behavior during uncertainty
Coordination protocols have failure and recovery properties beyond their success path. Describe blocking, timeouts, and durable decision recovery accurately.
59.A service forgets idempotency keys after one hour, but clients may retry an old request after two hours. What scope limit should be documented?
Show answer and explanation
- Keys never need retention because request bodies exist.
- The client automatically learns that the first request committed.
- Every retry is still guaranteed exactly-once.
- Duplicate suppression does not cover that whole retry window.
Answer: Duplicate suppression does not cover that whole retry window.
Retention and retry policy must align with the promised behavior. Expired identity records can allow an old operation to be applied again.
60.A message transport advertises exactly-once handling within its own transaction scope. A handler also sends an unrelated external email. What must be analyzed separately?
Show answer and explanation
- Only whether the message contains an address
- The email effect's own coordination and retry semantics
- A guarantee the transport makes every external effect exactly-once
- Only the transport's partition count
Answer: The email effect's own coordination and retry semantics
A guarantee at one boundary does not automatically cover arbitrary external systems. Make the end-to-end effect scope explicit.
61.An endpoint uses PUT but appends a new charge on every repeated identical request. What should an API review examine?
Show answer and explanation
- Only the HTTP method's spelling
- Only the response's content type
- Whether actual behavior matches its idempotent contract
- A guarantee a method name enforces server semantics
Answer: Whether actual behavior matches its idempotent contract
Protocol expectations must be implemented by the service. A method label does not make repeated side effects idempotent.
62.A cancellation request races with job completion. Both attempt conditional transitions from running. What should the state machine prevent?
Show answer and explanation
- Only a change in displayed progress percentage
- Every completion after the job starts
- Every cancellation attempt from returning any status
- Two incompatible terminal transitions both being accepted
Answer: Two incompatible terminal transitions both being accepted
An atomic state transition can arbitrate the race. Define what callers observe when cancellation arrives after completion has already won.
63.A client deadline expires while a durable job continues on the server. What must the caller avoid inferring solely from that deadline?
Show answer and explanation
- That it stopped waiting for a response
- That the job was canceled or rolled back
- That the outcome could still become successful
- That a later status query may be useful
Answer: That the job was canceled or rolled back
Client waiting limits and server effect completion are separate. A cancellation or rollback guarantee requires an actual mechanism and contract.
64.Two concurrent identical requests use one idempotency key. What should their handling coordinate?
Show answer and explanation
- A guarantee separate local caches coordinate automatically
- A single logical result and effect boundary
- Only matching response status text
- Only the order of connection establishment
Answer: A single logical result and effect boundary
Concurrent attempts must share a durable decision or suitable atomic identity protocol. Identical payloads alone do not prevent duplicate effects.
65.A create request includes a quoted price and its version. The current price changes before fulfillment. What must the service contract define?
Show answer and explanation
- Only the current cached price
- Only whether both prices use the same numeric type
- Which price version governs acceptance and execution
- A guarantee the oldest price is always binding
Answer: Which price version governs acceptance and execution
Concurrency exposes business semantics, not just database races. Define the applicable version and enforce it at the promised boundary.
66.Initially x=y=0. T1 reads x=0 and writes y=1. T2 reads y=0 and writes x=1, and both commit those reads and writes. Can that history equal a serial execution of these transactions?
Show answer and explanation
- Yes; separate writes guarantee serializability.
- No; serial execution can never write two variables.
- Yes; any final state is serializable.
- No; either serial order changes one read.
Answer: No; either serial order changes one read.
If T1 ran first, T2 would read y=1. If T2 ran first, T1 would read x=1. The observed pair of zero reads has no matching serial order.
67.A wallet starts at 50. An atomic operation adds 12 and another subtracts 7, with both effects committed exactly once. Ignoring limits and other work, what is the final balance?
Show answer and explanation
- 55
- 45
- 69
- 50
Answer: 55
The specified effects give 50+12−7=55. This arithmetic expectation does not itself establish that an implementation applied both effects once.
68.A system acknowledges a write while its only copy remains volatile. The server then loses that memory. What promise needs scrutiny?
Show answer and explanation
- A guarantee acknowledgment implies persistence in every design
- Only the write's field types
- Only isolation between readers
- Durability of the acknowledged write
Answer: Durability of the acknowledged write
An acknowledgment's meaning depends on its durability boundary. State what failures the persisted or replicated record is designed to survive.
69.A fencing-aware resource has accepted token 42. It later receives a write with token 39, under a rule rejecting tokens below the greatest accepted token. What should it do?
Show answer and explanation
- Accept if the worker says it still owns a lease.
- Reset the greatest token to 39.
- Reject the stale-token write.
- Accept because 39 was once a valid token.
Answer: Reject the stale-token write.
The supplied comparison rejects 39<42 at the resource boundary. Ownership claims from an older worker do not override the rule.
70.A conditional debit requires balance>=amount and subtracts amount atomically. Starting at 9, two debits of 6 compete on the same row. If no overdraft is allowed and no other work occurs, how many can succeed?
Show answer and explanation
- 3
- 1
- 0
- 2
Answer: 1
The first successful debit leaves three, which cannot satisfy the next six-unit debit. The conditional state change must be genuinely atomic.
71.A lock operation protects only rows that currently exist. A query finds no reservation row and acquires no range lock. What should the application not infer?
Show answer and explanation
- That a separate enforcing constraint could be useful
- That the query returned no rows at that time
- That the relevant resource may require broader coordination
- That concurrent insertion of a reservation is prevented
Answer: That concurrent insertion of a reservation is prevented
Locking existing rows is not automatically protection of absent keys or predicates. Use the configured database semantics and actual invariant.
72.An API reads a parent and its children in separate transactions while another operation moves a child. What can a combined response contain?
Show answer and explanation
- A proof that each individual read was dirty
- A view that never existed as one consistent state
- A guarantee of one shared snapshot
- Only changes committed after the response finished
Answer: A view that never existed as one consistent state
Individually valid reads can come from incompatible points in time. A consistent aggregate response needs a suitable read boundary or qualified semantics.
73.A state machine records transitions but allows completed→running without an explicit recovery rule. What should design review define?
Show answer and explanation
- The legality and meaning of that transition
- Only the display color of completed jobs
- A guarantee every state transition is reversible
- Only the numeric order of state IDs
Answer: The legality and meaning of that transition
A state enum does not by itself define valid histories. Specify allowed transitions, preconditions, and recovery semantics.
74.An update records the new state but not the operation identity or prior revision. What can an audit struggle to establish?
Show answer and explanation
- The fact that a row currently exists
- The field's declared type
- The new state's current stored value
- Which request caused the change and from which version
Answer: Which request caused the change and from which version
Current state alone may not support causal or historical reconstruction. Retain appropriate operation and version evidence for the required audit scope.
75.A deduplication key is unique per tenant, but the database constraint uses key alone across all tenants. What problem can occur?
Show answer and explanation
- Unrelated tenants' operations can collide.
- Every tenant is guaranteed isolation from false conflicts.
- Only the result's sort order changes.
- The constraint must allow every duplicate within a tenant.
Answer: Unrelated tenants' operations can collide.
The uniqueness scope must match the business identity. A composite tenant-and-key constraint may be needed under this contract.
76.A database table stores amounts in integer minor units. A transfer computes 0.1+0.2 in binary floating point before converting. What should be reviewed?
Show answer and explanation
- Only the row's primary key
- Only whether the database column is nullable
- Rounding and amount-representation semantics
- A guarantee binary floating point exactly represents every decimal amount
Answer: Rounding and amount-representation semantics
Amount arithmetic needs a consistent precision and rounding contract. Integer storage does not undo errors introduced before conversion.
77.A request passes validation against version 5 of an object. Before execution, the object changes to version 6. What can bind the decision to the state it evaluated?
Show answer and explanation
- Only the earlier successful validation response
- A guarantee validation freezes all later state
- Only the object's unchanged display name
- A checked version precondition at execution
Answer: A checked version precondition at execution
Validation and use can race. A suitable precondition or protected transaction can detect that the decision's assumptions are stale.
78.A transaction calls a non-idempotent payment provider and then aborts locally. Why is automatic whole-transaction retry dangerous without another protocol?
Show answer and explanation
- The provider's action must roll back with the database.
- The local abort proves no payment exists.
- Retrying SQL always preserves every external effect exactly once.
- The external action may already have occurred.
Answer: The external action may already have occurred.
External work can survive a local abort. Separate or coordinate it with durable identity, reconciliation, or an appropriate workflow protocol.
79.A system uses a savepoint to roll back one optional substep. What must the implementation verify about preceding work?
Show answer and explanation
- That a savepoint commits all external calls
- Whether it remains within the still-active outer transaction
- That every earlier statement has become independently durable
- That the outer transaction can no longer fail
Answer: Whether it remains within the still-active outer transaction
A savepoint is a subtransaction control mechanism under the database's contract. It is not the same as a final durable commit of all earlier work.
80.A request reads inventory from one region and writes a reservation in another under asynchronous replication. What needs explicit design?
Show answer and explanation
- The consistency boundary for the shared inventory invariant
- A guarantee asynchronous replication supplies synchronous global ordering
- Only the regional hostname format
- Only the number of regions displayed
Answer: The consistency boundary for the shared inventory invariant
Geographic placement and replication mode affect available guarantees. State how conflicting allocations are prevented or reconciled.
81.A test launches many concurrent requests but checks only that all responses are HTTP 200. What correctness evidence is missing?
Show answer and explanation
- The fact that successful statuses were returned
- The ability to inspect each response
- The resulting state and allowed histories
- The number of launched requests
Answer: The resulting state and allowed histories
Response codes alone do not establish exactly-once effects, invariant preservation, or a valid concurrency history.
82.A race test relies on a fixed sleep to make two threads collide. What can make it more informative and reproducible?
Show answer and explanation
- Only rerunning until the expected failure appears
- Explicit synchronization at the intended interleaving
- Only a longer arbitrary sleep
- A guarantee scheduling is identical across machines
Answer: Explicit synchronization at the intended interleaving
Barriers or controlled hooks can exercise a specific window. Stress and randomized schedules add different evidence but do not replace a defined test condition.
83.A failure-injection test crashes after commit but before sending the response. Which behavior is particularly useful to check?
Show answer and explanation
- Only whether the request log has one line
- A guarantee the transaction was never durable
- Only whether the client saw a timeout
- Recovery of the same logical result without duplicate effects
Answer: Recovery of the same logical result without duplicate effects
This window creates an ambiguous client outcome. Verify the protocol's intended retry and status-recovery behavior at the effect boundary.
84.An idempotency test retries only after a clean first response. What important case remains?
Show answer and explanation
- Retry after an ambiguous first outcome
- Only repeating a request with no side effects
- Only parsing the original response body
- Only checking the first response's field names
Answer: Retry after an ambiguous first outcome
The difficult case is uncertainty about whether the effect occurred. Test crash and lost-response windows, not only an ordinary completed call.
85.A property test checks that transfers preserve total funds for random accounts. What additional condition is needed to detect money sent to the wrong account?
Show answer and explanation
- Account-level debit and credit assertions
- Only nonnull transaction IDs
- Only another total over the same accounts
- A guarantee total preservation identifies the correct recipients
Answer: Account-level debit and credit assertions
Global conservation does not specify routing. Compare the expected per-account effects and relevant authorization or identity constraints.
86.A concurrency test finds a final counter of 100 after 100 requests. Does that alone prove every request was applied exactly once?
Show answer and explanation
- No; a counter can never be tested.
- Yes; the count proves real-time ordering.
- Yes; equal totals prove every individual history.
- No; lost and duplicate effects could cancel in the total.
Answer: No; lost and duplicate effects could cancel in the total.
Aggregate agreement can conceal offsetting mistakes. Use operation identities and histories to test the claimed property.
87.A history checker considers only invocation order and ignores response times. Which property can it fail to assess correctly?
Show answer and explanation
- The set of operation names
- Real-time precedence for linearizability
- The number of invoked operations
- The existence of recorded arguments
Answer: Real-time precedence for linearizability
Linearizability depends on invocation and completion intervals, including nonoverlapping operations' precedence. An invocation list alone omits that information.
88.A test verifies one permissible ordering of concurrent operations but rejects another ordering the contract also permits. What should be corrected?
Show answer and explanation
- The oracle's allowed-history model
- Only the implementation's thread count
- Only the test's timeout value
- A guarantee concurrency has one universal schedule
Answer: The oracle's allowed-history model
A sound oracle should accept every behavior permitted by the specified contract while rejecting violations. Overly narrow expectations can create false failures.
89.A deployment changes an invariant from allowing zero balance to requiring strictly positive balance. Existing zero-balance records remain. What must migration planning include?
Show answer and explanation
- Only the new validation function's unit tests
- Only the application version label
- Existing-state compatibility and transition rules
- A guarantee changing code rewrites every stored row
Answer: Existing-state compatibility and transition rules
A new rule must address historical state and mixed-version behavior. Code changes alone do not make existing data satisfy it.
90.A rolling deployment has old writers that omit a newly required field. New readers assume it is always present. What must be coordinated?
Show answer and explanation
- Only the order of package installation
- A guarantee all nodes switch atomically by default
- Writer, stored-data, and reader compatibility
- Only the newest reader's successful startup
Answer: Writer, stored-data, and reader compatibility
Schema evolution spans actual writer versions, retained records, and reader assumptions. Plan the transition rather than rely on a single component's update.
91.A constraint is enforced in one HTTP handler but bypassed by an import job. What scope should correctness review cover?
Show answer and explanation
- Every path that can change the protected state
- Only the busiest HTTP endpoint
- A guarantee internal jobs cannot violate business rules
- Only requests from interactive users
Answer: Every path that can change the protected state
The invariant concerns all relevant writers. A separate trusted path can still introduce incorrect state if it bypasses required enforcement.
92.A database constraint rejects duplicate operation keys, but the handler converts that rejection into a generic success with a new result body. What should be recovered instead when the contract promises one result?
Show answer and explanation
- Only a new random operation ID
- The established result or an explicit pending/conflict state
- A guarantee duplicate detection determines every response field
- A fabricated result unrelated to the first attempt
Answer: The established result or an explicit pending/conflict state
Recognizing an existing operation is not the same as reconstructing its outcome. Return the durable result or a truthful state under the API contract.
93.A transaction retries indefinitely under contention. What operational requirement should the policy include?
Show answer and explanation
- Only a longer database connection timeout
- Only suppressing conflict logs
- A bounded budget and a truthful failure outcome
- A guarantee every request eventually commits within its deadline
Answer: A bounded budget and a truthful failure outcome
Retries consume resources and may never succeed before a deadline. Bound them and preserve clear semantics when the budget is exhausted.
94.A long-running transaction pins an old snapshot while rows are updated repeatedly. What resource effect may need monitoring in an MVCC system?
Show answer and explanation
- A guarantee every update is physically blocked
- Automatic reduction of storage to one version
- Retention of old versions and related maintenance pressure
- Only a change in result-column order
Answer: Retention of old versions and related maintenance pressure
Snapshot lifetime can delay reclamation of versions needed by readers. Exact maintenance behavior depends on the database implementation.
95.A transaction isolation setting is configured on one connection, but the request uses a different pooled connection. What must be verified?
Show answer and explanation
- Only the pool's maximum connection count
- The actual execution connection's settings
- Only the configuration function's return value
- A guarantee all connection state is global
Answer: The actual execution connection's settings
Connection-local state does not automatically apply to another connection. Set and verify the intended transaction context where work actually executes.
96.An operation depends on an authorization version as well as a data version. Only the data version is checked before committing. What stale assumption can remain?
Show answer and explanation
- The identity of the data version already checked
- A guarantee permission state never changes during a request
- The authorization decision
- The number of fields in the update
Answer: The authorization decision
Concurrency can invalidate permission as well as data assumptions. The required validation boundary must match the authorization contract.
97.A monotonically increasing entity revision is reset during an import. Consumers discard every revision below their last seen value. What can occur?
Show answer and explanation
- Every consumer automatically resets its state.
- Only duplicate payload bytes are affected.
- The import guarantees global ordering.
- Legitimate imported updates can be ignored.
Answer: Legitimate imported updates can be ignored.
Version protocols need a consistent lifetime and reset policy. Resetting one producer can conflict with downstream monotonicity assumptions.
98.A service's transaction log shows one committed operation, but two external notifications were sent. What should the claimed guarantee distinguish?
Show answer and explanation
- Database commit count from notification effects
- Only the size of the transaction record
- Only the HTTP response status
- A guarantee one database commit implies one external send
Answer: Database commit count from notification effects
Different boundaries can have different repetition behavior. Test and describe the effect that the consumer actually depends on.
99.A design claims linearizable reads from every replica while replication can lag and no read coordination is used. What should review demand?
Show answer and explanation
- A mechanism or evidence supporting that real-time guarantee
- A guarantee asynchronous copying implies current reads
- Only equal schemas on every replica
- Only the replica count
Answer: A mechanism or evidence supporting that real-time guarantee
A consistency claim must match the protocol and failure assumptions. Schema agreement does not establish real-time visibility of completed writes.
100.A durable operation key K maps to a committed order O. The response was lost. A retry supplies K and the same request fingerprint. Under a stored-result idempotency contract, what should the retry return?
Show answer and explanation
- The recorded result for O
- A new order with another ID
- An automatic rollback of O followed by recreation
- Success without identifying any order
Answer: The recorded result for O
The logical operation already has a durable result. Replaying that result avoids a second effect and resolves the client's ambiguous outcome under the stated contract.
101.Capacity is 10. Two requests each read reserved=4 and plan to reserve 4 more. Both overwrite reserved with 8 after independently approving themselves. Why is reserved=8 not sufficient evidence of correctness?
Show answer and explanation
- It proves only one request was accepted.
- It can hide two accepted reservations totaling 12.
- It proves the capacity invariant held for all effects.
- It proves both increments were atomically applied.
Answer: It can hide two accepted reservations totaling 12.
The counter can lose an update while both callers receive approval. Reconcile logical reservations and their sum, not merely the final stored counter.