Skip to content

Design, then what broke · Monzo · 8 min

A bank backend designed in 2016

In 2016 Monzo published how it was building a bank from small services. In 2017 and 2019 it published two outages. Read the design, then see which parts of it the outages ran through.

Most design write-ups stop at the diagram. This one has a second half, because the same company later published honest accounts of two outages. Put side by side, they show something a design review rarely can: which choices carried the failure when it came.

The design below is as Monzo described it in September 2016, when the bank was still in beta. It is not a description of how Monzo runs today.

The design post: Building a modern bank backend ↗, Oliver Beattie, Head of Engineering, 19 September 2016.

The ask, in 2016

What the design had to do

  • Available around the clock: no maintenance windows and no daily batch runs.
  • No single point of failure.
  • Able to grow to hundreds of millions of customers.
  • Easy to extend: new features in hours, not months.
  • A card payment answered within tens of milliseconds.
Backend developers at the start
3
Services at the time of writing
about 150
Card approve or decline
tens of ms
Infrastructure cost after the move
about a quarter

Part 1

The design, choice by choice

  1. Choice 1

    Small services from the first day

    What they chose
    The backend is a collection of small services instead of one application. There were nearly 100 by the time the beta opened and about 150 when the post was written, built by a team that began with three backend developers.
    Why
    The post argues that one large codebase stops scaling as users and developers grow. Each team should be able to build, deploy and scale its own part without waiting for the others.
    What it costs
    The post itself calls this unusual for a company so young. Hundreds of services only work if something schedules them, routes between them and carries their messages, and those shared parts are the next three choices.

    Learn it:Monolith or services?Shared dependencies and blast radius

    Later, an outage ran through this:29 July 2019

  2. Choice 2

    One scheduler packs every service onto shared machines

    What they chose
    Services are packaged as containers and placed on machines by Kubernetes, running on AWS. Monzo moved to it after about a year on Mesos and Marathon. When a machine dies, its containers are started somewhere else, and build jobs run on spare capacity.
    Why
    Packing services tightly cut the cost of production infrastructure to about a quarter of what it had been, and dedicated build machines were no longer needed.
    What it costs
    The post is plain that running Kubernetes with high availability on AWS "is not for the faint of heart" and needs a deep understanding of how it works inside. The cluster's own store, etcd, becomes something every service depends on.

    Learn it:Service discovery

    Later, an outage ran through this:27 October 2017

  3. Choice 3

    Every call between services goes through a local proxy

    What they chose
    Services talk plain HTTP to a proxy on their own machine, and the proxy finds the destination. Monzo used linkerd, one per machine, which learns where each service runs from Kubernetes. It balances load by comparing two random servers on recent latency, retries only requests that are safe to repeat, within a budget, and can send a share of traffic to a new version.
    Why
    DNS round robin is, in the post's words, "quite a blunt instrument". Putting balancing, retries and routing in a proxy gives them to every service in every language at once, instead of rebuilding them in each library.
    What it costs
    Every call in the bank now depends on the proxy and on what the cluster tells it. The post mentions that Monzo had already found and fixed a few bugs in how linkerd worked with Kubernetes.

    Learn it:Sidecar proxyRound robin vs least connectionsRetry storms across layersCanary rollout

    Later, an outage ran through this:27 October 2017

  4. Choice 4

    A replicated log for work that can wait

    What they chose
    Work that need not finish inside the request goes through Kafka, which the post describes as a replicated log where each consumer keeps its own position. Messages are stored, can be replayed, and are delivered at least once.
    Why
    The card answer must come back within tens of milliseconds, but much of what follows a payment can happen afterwards. Publishing has to keep working even when the consumers are down.
    What it costs
    At least once means sometimes twice. The post says exactly-once delivery is "generally impossible", so every consumer has to cope with seeing the same message again.

    Learn it:Offsets and at-least-onceIdempotency keys

  5. Choice 5

    Shared code lives in services, not in libraries

    What they chose
    Go is the main language, but services have also been written in Java, Python and Scala. Common needs are provided as services that any language can call. Distributed locking, for example, is a service in front of etcd.
    Why
    A shared library has to be written again for each language. A shared service needs only a small client, and the post adds that quotas, rate limits and access control are easier to apply at a service.
    What it costs
    A library fails inside one service. A shared service that is slow or wrong is slow or wrong for everyone who calls it, so each one needs its own care over timeouts and failure.

    Learn it:Split brain and fencing

  6. Choice 6

    Left for a later post: where the data lives

    What they chose
    The 2016 post does not describe the database. It names data storage as the subject of a follow-up. Monzo's 2019 write-up fills the gap: one Cassandra cluster of 21 servers, shared by every service, each with its own keyspace. Each piece of data is kept on three servers.
    Why
    The 2019 write-up says every read and write needs two of the three copies to agree. When the cluster runs close to its limits, capacity is added by adding servers to it.
    What it costs
    The services are separate, but their data sits in one cluster. The 2019 write-up says Monzo had run a single cluster for all services "for a long time" and now plans to split it into several smaller ones.

    Learn it:Quorum reads and writesA database shared between services

    Later, an outage ran through this:29 July 2019

Part 2

Then what broke

Both outages are puzzles on this site. Each card below shows only what the team saw. Play the puzzle to work out the cause, or open the answer here.

  1. 27 October 2017 · 13 months later

    The proxy every call goes through

    A routine deploy to a payments service fails, and rolling it back does not help. To clear things up, the team restarts every routing proxy, several hundred of them. Now no service can reach any other.

    Ran through:One scheduler packs every service onto shared machinesEvery call between services goes through a local proxy

    Work it out yourself: play the 90-second puzzle
    Show what happened (spoils the puzzle)

    Two weeks earlier the etcd cluster behind Kubernetes had been upgraded and grown from three nodes to nine, and the upgrade went to plan. A Kubernetes bug triggered by that change stopped linkerd from learning where newly started copies of a service were. So the deploy at 14:10 could not be reached, and neither could its rollback. At 14:26 the team restarted every proxy. The restarted proxies hit a second incompatibility: they could not read a service that had no running copies, and one had been left in that state the day before. Nothing could serve requests until those empty services were deleted at 15:31.

    Back to the design: The proxy gave every service balancing and retries without extra work. It also meant that one parsing bug, in one component, could stop every call in the bank. Monzo's own account calls the restart well-intentioned and a poor decision that made the outage worse.

    Monzo community: the 27 October 2017 outage, write-up by Monzo's Head of Engineering ↗
  2. 29 July 2019 · nearly 3 years later

    Rows that exist, but don't

    The database is running closer to its limits than the team would like, so they add six servers to the 21. A test with one server went fine. Minutes later, reads start returning 'not found' for records that are certainly there.

    Ran through:Small services from the first dayLeft for a later post: where the data lives

    Work it out yourself: play the 90-second puzzle
    Show what happened (spoils the puzzle)

    After the previous scale-up in October 2018, a flag had been set so that a replaced server would be restored from backup. The same flag decides whether a new server joins already active. The six new servers were expected to wait. Instead they took responsibility for part of the data and answered reads from empty disks. With one new server, two of the three copies still held the data. With six, some reads found a majority of empty servers. The servers were removed one by one between 14:18 and 15:08, and the data written in between was reconciled by 23:00. Monzo says it fully recovered the data.

    Back to the design: Each service had its own keyspace, so the services looked independent. Their data was not: one mistake in scaling the shared cluster reached every service at once, from card payments to in-app chat.

    Monzo: why Monzo wasn't working on 29 July 2019 (official postmortem) ↗

Spoilers for both puzzles

What to take from it

Show the 5 lessons (they give the causes away)
  1. 1. What helps every service can stop every service

    A shared proxy, scheduler or database removes work from each team and gathers the risk in one place. For each shared part, ask what happens when it is wrong, not only what happens when it is down. Both outages were shared parts giving wrong answers while still running.

  2. 2. The trigger and the cause were far apart

    The etcd upgrade was two weeks before the 2017 outage. The database flag was set nine months before the 2019 one. Neither caused trouble on the day it was made. When something breaks, the last deploy is the first suspect and often the wrong one.

  3. 3. Versions are part of the design

    Kubernetes, etcd and linkerd each worked. The 2017 failure was in how the versions in use worked together. A design diagram shows boxes, not version pairs, so the upgrade plan has to cover them.

  4. 4. Doing it to one is not doing it to all

    Adding one database server was safe, because the other copies still formed a majority. Adding six was not. Restarting one proxy looked safe. Restarting all of them exposed a second bug with nothing left to fall back on.

  5. 5. The design is not the villain

    Neither write-up blames the 2016 choices. Each choice bought something real and brought a way to fail with it. A good design review names that failure for every shared part before production does.

Sources: Monzo: Building a modern bank backend (19 Sep 2016) ↗ · Monzo community: the 27 October 2017 outage, write-up by Monzo's Head of Engineering ↗ · Monzo: why Monzo wasn't working on 29 July 2019 (official postmortem) ↗ · Report a problem

The design is as Monzo described it in 2016, not how it runs today. Everything here paraphrases Monzo's own published accounts, linked above. All wording is original. BuildBreak is not affiliated with Monzo.