Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

Design the REST resources for a bank transfer between two accounts, including how a client learns the transfer's outcome when processing takes several seconds. Where would you use synchronous responses and where asynchronous ones?

We model the transfer itself as a resource: POST /transfers creates it and GET /transfers/{id} returns its state. When processing takes seconds, POST returns 202 Accepted with a Location header and a status such as PENDING, and the client polls (guided by Retry-After) or receives a webhook when it becomes COMPLETED or FAILED. An idempotency key on POST makes retries safe, and we never let clients update two account balances themselves.

Background to this question

Money transfers are a favourite design question because they touch everything that makes APIs hard: a business operation that is not a simple record, work that does not finish within one request, retries over unreliable networks and the cost of getting it wrong. In this answer, we will recap why a transfer should be a resource of its own, design the endpoints, see where synchronous and asynchronous responses each fit, make the POST safe to retry, and look at how clients learn the outcome. We will also cover the transfer history and reversals.

1Why the Transfer Is a Resource

A resource in REST is any thing the API lets clients name and act on. It does not have to be a database table. A transfer between two accounts is a business event with its own identity, its own lifecycle (requested, processing, done or failed) and its own data such as amount, currency and reference. That makes it a natural resource.

The tempting alternative is to let the client call PUT /accounts/A with a lower balance and PUT /accounts/B with a higher one. This is wrong for two reasons. It leaks the bank's internals, because the client now decides how balances change, and it cannot be atomic: if the second call fails, money has disappeared, and nothing on the client side can undo that reliably. The server must own the whole operation, so the client asks for a transfer and the server carries it out.

2The Endpoints

The design needs only a few endpoints. The client creates a transfer and then reads it.

Java
POST /transfers
Idempotency-Key: 6f1c2b7e-0d1a-4a8e-9f55-2c1b9b0a7d10
Content-Type: application/json
{ "fromAccount": "ACC-1001", "toAccount": "ACC-2002",
"amount": "250.00", "currency": "EUR", "reference": "Invoice 77" }
HTTP/1.1 202 Accepted
Location: /transfers/tr_8812
Retry-After: 2
{ "id": "tr_8812", "status": "PENDING", "createdAt": "2026-11-05T10:15:02Z" }
GET /transfers/tr_8812
HTTP/1.1 200 OK
{ "id": "tr_8812", "status": "COMPLETED", "completedAt": "2026-11-05T10:15:05Z" }

Notice that the amount is a string with two decimals plus a currency code, never a floating-point number, so no client rounds 0.1 + 0.2 into a different amount. The status field moves through PENDING, then COMPLETED or FAILED, and a FAILED transfer carries a reason such as INSUFFICIENT_FUNDS so the client can show something useful.

3Synchronous or Asynchronous?

If the transfer is between two accounts in the same ledger and finishes in a few hundred milliseconds, the simplest answer is synchronous: POST returns 201 Created with the finished transfer in the body. The client gets its answer in one call, which is easier for everyone.

When processing takes several seconds, because of fraud checks, a payment network or a core banking system, holding the HTTP request open is fragile. Mobile networks drop it, gateways time out at 30 or 60 seconds, and a client that times out has no idea whether the money moved. So we accept the request quickly, store the transfer as PENDING, return 202 Accepted with a Location header pointing to the transfer, and do the work in the background. Reads of state stay synchronous; only the slow write becomes asynchronous. A useful rule is to decide per operation by its slowest realistic duration, not its average.

Step throughA slow transfer with 202 and polling
ClientTransfer APIProcessor
POST /transfers + Idempotency-Key
store transfer as PENDING
202 Accepted, Location /transfers/tr_8812
process tr_8812 (queue)
GET /transfers/tr_8812
200 PENDING, Retry-After: 2
mark COMPLETED
GET /transfers/tr_8812
200 COMPLETED

9 messages in order. Play them, or step through them one at a time.

The client always has a URL to ask, even after a timeout.

4Making POST Safe to Retry

POST is not idempotent: sending it twice normally creates two resources. For money that means two transfers. So we require an Idempotency-Key header, a unique value the client generates once per intended transfer and reuses on every retry. The server stores the key with the transfer under a unique constraint. If the same key arrives again, the server returns the existing transfer instead of creating a new one, and if the same key arrives with a different body, it rejects the request with 422 or 409.

Java
@PostMapping("/transfers")
ResponseEntity<TransferDto> create(@RequestHeader("Idempotency-Key") String key,
@Valid @RequestBody TransferRequest req) {
Transfer t = transfers.createOrGet(key, req); // unique (client_id, key) in the table
return ResponseEntity.accepted()
.location(URI.create("/transfers/" + t.id()))
.header(HttpHeaders.RETRY_AFTER, "2")
.body(TransferDto.of(t)); // a replay returns the same id
}

Because the response always contains the transfer id and Location, a client that lost the first response can retry with the same key and land on the same transfer.

5Telling the Client the Outcome

Polling is the baseline every client can use: GET the transfer until its status is final, waiting as long as Retry-After says. It is simple, works through firewalls and needs nothing from the client but HTTP. For partners or internal systems, we can add a webhook, an HTTP callback to a URL the client registered, or publish a TransferCompleted event on a message broker. Push mechanisms reduce polling traffic, but they can be lost or duplicated, so the transfer resource stays the source of truth and clients use it to confirm.

6Follow-up questions

How would you expose the transfer history of one account?

As a sub-collection that is filtered and paged by the server, for example GET /accounts/ACC-1001/transfers?direction=outgoing&from=2026-10-01, returning transfers in which the account is the source or the target, newest first, with cursor pagination because history only grows. Each item links to its /transfers/{id} resource. The server checks that the caller may see that account, and the history is a read model, so it can be served from a replica or a projection without touching the ledger.

What changes if transfers must be reversible?

A reversal must not edit or delete the original transfer, because the history has to show both events for audit. Instead we create a new resource, for example POST /transfers/tr_8812/reversals, which produces a compensating transfer in the opposite direction with its own id, status and idempotency key. The original gains a status or link such as REVERSED pointing at the reversal. Rules such as a time limit or requiring funds in the target account are enforced by the server when the reversal is requested.

Why not return 200 instead of 202 for the slow case?

200 or 201 tells the client the work is done. 202 Accepted says the request was valid and accepted for processing but has not finished, which is exactly the truth. Clients and tooling then know they must look at the status before treating the money as moved.

7Conclusion

In this answer, we modelled a bank transfer as its own resource instead of two balance updates the client cannot make atomic. POST /transfers creates it and GET /transfers/{id} shows its state. Fast transfers can answer synchronously with 201, while slow ones return 202 Accepted with a Location and a PENDING status. An idempotency key makes retries safe, and clients learn the outcome by polling with Retry-After, with webhooks or events as an optional push on top.

What to say in the interviewAbout 70 seconds aloud

Open with

I would make the transfer itself the resource. The client sends POST /transfers with the source account, target account, amount as a decimal string, currency and a reference, and the server owns the whole operation.

Then, if they want more

I would never let a client PUT two account balances, because that exposes our internals and the client cannot make two calls atomic. If the transfer completes in a few hundred milliseconds, I would answer synchronously with 201 Created and the finished transfer.

If it takes several seconds because of fraud checks or an external network, I would store it as PENDING, return 202 Accepted with a Location header to /transfers/{id} and a Retry-After, and process it in the background.

The client polls that resource until the status is COMPLETED or FAILED, and partners can additionally register a webhook or consume a completion event, but the resource remains the source of truth. POST must carry an Idempotency-Key that the client reuses on retries, so a timeout followed by a retry returns the same transfer rather than moving the money twice. Reversals would be new compensating transfers, not edits to the original.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design the REST resources for a bank transfer between two accounts, including how a...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/7f25d9fc88/