Home›Design›A digital bank (Monzo), send money
Design · System design X-ray

A digital bank (Monzo): send money to a friend

Sending money looks like one tap. Behind it, a bank has to decide, record and deliver the payment without losing it. Switch between 2016 and the larger system that followed. Tap any box for what it does, why it is there, and what Monzo has published, with the source. Where Monzo has said nothing, the box says so.

The X-ray

Follow one payment

Press a request to watch it travel. Facts come from Monzo's own blog posts and talks, listed at the end. Idempotency keys are generic background, not a claim about Monzo.

The story

From a fast card answer to a bank that checks itself

The tap

It is 2016. Monzo has nearly 100 services, most written in Go, and three backend developers at the start. You tap your card and the network wants an answer in tens of milliseconds. Everything else, such as merchant details, push notifications and the feed, happens after the answer.

Work that cannot be lost

That later work is queued, not dropped. The 2016 post says these steps must never be skipped, and picks Kafka for replication, persistence, at-least-once delivery and replay. At-least-once means a message can arrive twice. That is why bank code needs idempotency keys, so a repeat is recognized and not paid twice. This last point is general background. Monzo has not described its own design in the posts used here.

A spike on purpose

In December 2018 the crowdfunding round raised 20 million pounds from about 36,000 investors in under three hours. Monzo split it in two. A fast layer told investors at once if they could invest, using in-memory counters. A second layer moved the money from a queue at about 60 a second.

One database, many services

Cassandra became the core database. More than 500 services used it by 2019, at about 300,000 reads a second at peak. Cassandra has no transactions, so Monzo writes the index tables first and the canonical table last. On 29 July 2019 a scale-up added six nodes to a cluster of 21 without their data. Balances looked wrong until it was fixed. Monzo planned to split the one large cluster into smaller ones.

Durable before you answer

A Faster Payments outage on 30 May 2019 led Monzo to run its own gateway, live on 2 November 2019. It writes each message durably to disk before it answers, copies the log across six SSDs, and runs in two data centers at once. The team accepted lower throughput to get durability.

Equal and opposite

The ledger is double entry, and balances are sums of entries. Each payment system has dozens of coherence checks. Each day the ledger is compared with the settlement account, and any mismatch is a reconciliation break with an owner and an audit log. Fraud checks run before money moves: the 2023 talk names financial crime services among those called in real time, and does not describe their rules.

Small changes, often

By 2020 there were about 1,600 services, and about 2,500 in 2023. In 2022 Monzo deployed over 100 times a day. One command deploys, the pipeline refuses a version that never ran on staging, and the owning team reviews. Alerts go to the team that owns the service.

The design docs behind it

Each part of this system has its own design doc: Payments and ledgers · Audit and event logs · Accounts and sessions. The whole story starts at System design 1: one server.

Decisions you can reuse

What to take from it

Write durably, then answer

Monzo's Faster Payments gateway writes each message to disk, copied across machines, and chose durability over speed. Never tell a customer "sent" before the record is safe. See System design.

Use a double-entry ledger

Never edit a balance. Write equal and opposite entries and sum them. Every balance can then be explained and checked.

Make retries safe (generic)

Queues that deliver at least once, and phones that retry, mean the same request can arrive twice. An idempotency key lets the server spot a repeat and return the first result. Monzo has not published its own design in the posts used here.

Keep the answer path short

Decide in tens of milliseconds. Do enrichment and notifications on a queue that cannot lose them.

Check after the fact

Coherence checks and daily reconciliation find what tests missed. Break reports need an owner and an audit trail.

Plan for the database change itself

The July 2019 outage came from adding capacity. Document settings, write runbooks and keep clusters small. See Database families.

Part 3 of 4 · Design · 28 pagesAll pages

Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.