The weekly letter from Systems Thinking Lab: systems thinking insights for junior engineers, framed through the seven building blocks.
You are saving profile pictures as base64 text in a database column. Base64 is a way of writing a binary file, here an image, as ordinary text characters, so the picture can sit in a text field of a row, right next to the username.
It works. It deploys clean, it renders fine, and nobody complains. That is what a working first version looks like, and it is a reasonable place to start. It is also worth a closer look.
Here is what it costs. Every time anyone reads that row, even with a query that only wanted the username, the full image comes with it. Those bytes move through the database's own memory and out over its network path, whether the caller asked for them or not.
The bytes are also bigger than they need to be. Base64 inflates the data by about a third. So the table that holds your smallest, most-read rows, the ones fetched dozens of times in a single page load, becomes the fattest table in your system.
The two blocks involved explain why. A Relational Database is built to hold structured rows that you query: a username, an email, a date. A File Store is built to hold large files, such as images, videos and PDFs, and you fetch each one by its address. The column asks the first block to do the second block's job.
The fix is small. The picture goes in the File Store, which hands back a URL for it. The row keeps only that URL, a few bytes of text: the file's path. The picture then travels straight from storage to the browser and never touches the database.
You do not store the picture next to the username. You store the address of where the picture lives.
There is one case where the column is fine: the image is tiny, almost never read, and never shows up in a list. Most profile pictures are not that.
Here is the part I care about most. This was never a rule about images. It is one question, asked of each piece of data: which block is built for this?
A large file belongs in the File Store. A structured row you query belongs in the Relational Database. A value you look up by a key belongs in the Key-Value Store. Work that can wait belongs on a Queue, with a Worker to pick it up. The question stays the same each time, and the answer comes from what each block is built to do.
There are ten pieces to ask it with: seven building blocks and three external entities, the User, the External Service and Time. Ten is a small enough set to hold in your head, and it is enough to ask the question about a system you have never seen. Knowing the blocks this way also helps in system design interviews.
Next time you read a schema, pick one column and ask it. Does this belong in a row, or does it belong somewhere else, with the row keeping its address?
Kay
P.S. Course I teaches the ten pieces one at a time, so the which-block question has an answer: https://systemthinkinglab.ai/courses-i-iv.html