Episode 2 of 9 · Slack
The monolith that never died: what Slack kept in five million lines
Vertical version.
Chapters
Narration
You open Slack and type a message. Behind that one click is a program that began in twenty fourteen. Today it has about five million lines of code, and it is still the front door of Slack. For the last decade, nearly every talk about big systems has said the same thing. Break the big program into many small ones. Slack heard the advice, and kept the big program. That sounds like a mistake. So what did Slack see in it that was worth keeping? Why should you care? Almost every team that grows meets this choice. Keep one big program, or split it into many small ones. Splitting sounds modern, and sometimes it is right. But it is expensive, and hard to undo. Slack's answer shows what to look for before you decide. So here is the question for the next few minutes. What was actually worth keeping? Here is the plan. First, the obvious fix, breaking it up. Second, what Slack found inside the big program, a blank slate. Third, the bill that comes with it. And fourth, what stayed, and what left. Stop one, the obvious fix. Picture the big program as one large workshop. Every kind of job happens in it, under one roof. Breaking it up means building many small workshops, one for each job. Each can be changed alone, and each can grow alone. That is the promise. Now the cost. Work that used to happen in one room now crosses the street. Every question between two jobs becomes a trip over a network. As an example, if one page needs six answers from six other workshops, that is six trips, every single time. And each workshop can now fail on its own. Hold that thought, because Slack looked at the choice from another side. Stop two, the blank slate. Slack's program is written in a language called PHP. The language is not the interesting part. The way it runs each request is. When a request arrives, the program starts it on a completely blank slate. Fresh memory, with nothing left over from anyone before. It does its work, sends the reply, and then everything it held is thrown away. Picture a clean desk for every visitor. Visitor leaves, desk is wiped. Now suppose request two has a bug, and scribbles garbage on its desk. Request three gets a new desk. The garbage was wiped with the rest. A bug in one request cannot reach the next. Engineers call that fault isolation. Now the arithmetic, as an example. Suppose every request leaks one small piece of memory, a mistake nobody noticed. In a program that stays running, those pieces pile up. After one million requests, that is one million leaked pieces, and the program swells until it falls over. On a blank slate, a request leaks one piece, and then the desk is wiped. One piece, wiped. The next request, one piece, wiped. The total never passes one. A million requests, and still one. So the blank slate is a safety net that costs nobody any thought. Remember the number, one. Stop three, the bill. A safety net like that is not free. It is prepaid, in two ways. First, nothing survives a request, so nothing can be remembered between requests. If the program looked something up a moment ago, the next request has to ask again. Second, a request cannot hold a line open to your laptop, because the request ends and the line would end with it. So anything that must remember has to live outside. That is why Slack keeps a separate memory store, called memcached, beside the program, and always will. Every lookup leaves the program and comes back. As an example, three lookups in a request is three trips, every time. Safety on one side, trips on the other. Stop four starts with what Slack did not do. It did not rewrite the program. It swapped the floor underneath it, one step at a time. In twenty fourteen it ran on plain PHP five. Then, in twenty sixteen, on a faster engine that ran the very same code. Then came a stricter language, where you can add types, rules about what each value may be, one file at a time. Then a strict mode, where a converted file is locked and can never slide back. That lock is a ratchet, a gear that only turns one way. The last step was not a choice. The fast engine stopped supporting PHP, so staying fast meant moving every last file. Now, what left. Slack did take some jobs out of the big program, but only a few. The realtime servers that hold your connection. The job queue. Search. Permissions. And the keys for encryption. Ask what they have in common. Each one has to remember something. A connection, a waiting list, an index, who may do what, a set of keys. And a blank slate remembers nothing. So the rule was simple. Only jobs that need memory left. Everything else, the ordinary logic of the product, stayed. Slack never cut the program apart. It grew a few organs around it. Three things to keep. One. Splitting a big program has a cost, because every question between the parts becomes a trip. Two. Slack kept its program for one property, a blank slate for every request, so one bug cannot reach the next. Three. A blank slate remembers nothing, so only the jobs that need memory left, and the rest stayed. The language was never the thing Slack protected. It was a request that starts clean and leaves nothing behind. Next, the database that holds your messages, and the rule that decides which machine keeps each one.
Based on the board The Monolith That Never Died.
Covered in Slack, the case study, One building or many: monolith, microservices and the strangler.
Saved in this browser, and to your account when you sign in.