Trade-offs in Software Engineering (and Why They’re Inevitable)
We see things we can’t fully comprehend and call them magic. That’s normal, right? The same thing happens in software engineering. There is no silver bullet.
You see something that is incredibly good and fast, and you wonder how it’s done. Yes, it’s amazing. But if you dig down the rabbit hole, you’ll almost always find a trade-off.
Even in the hardware ecosystem, trade-offs exist. Look at devices that no longer have a headphone jack. Removing the jack creates room for larger batteries. Sometimes these decisions are driven by regulations or other constraints in the hardware world, but I still see them as trade-offs.
Now, speaking of trade-offs in the software space: sometimes you reach a point where you want to implement something. You come up with the best approach, but you still have to sacrifice something to make it work.
In software engineering, a trade-off is a deliberate design compromise where you sacrifice one desirable quality or feature to gain another.
Sometimes at work, we need to encrypt certain data. This can involve encryption at rest, encryption in transit, or both. Doing both provides stronger protection, but it comes with additional costs in performance, complexity, and operations. When evaluating the trade-offs, you compare the options available and what you’re giving up in return. The questions you should always ask yourself are: Is it worth it? Will it solve my problem? Will there be extra overhead in the future? What resources do I have available? What is my end goal? These questions can influence your decision.
A good area I’ll focus on here is the database.
Databases are an amazing piece of software that store data. In my opinion, they are one of the best real-world examples of distributed systems. A database has to deal with the CAP theorem. It aims to be consistent, available, and fault-tolerant (partition-tolerant). I won’t go deeper into the internals and how amazing database engineering is. If you’ve ever looked at database internals, you know that databases are just software running on hardware, using the operating system’s higher-level APIs, with a lot of careful design and trade-offs. There are about eight key data structures that power modern databases. You can read more about them here: https://bytebytego.com/guides/8-data-structures-that-power-your-databases/
Let’s take a look at the Log-Structured Merge Tree (LSM Tree).
LSM is a type of data structure widely used by NoSQL databases like Cassandra, RocksDB, ScyllaDB, and others. It is a disk-based data structure used to store key-value pairs on disk. It buffers incoming writes and merges them into the disk in sorted, immutable batches. It trades read simplicity for write throughput. I won’t go deep into LSM trees here (I have a separate note for that), but I’ll list some of its main components:
WAL (Write-Ahead Log): A way the database maintains durability. It is append-only.
MemTable: An in-memory buffer holding recent changes (often implemented using a B-tree or similar structure).
SSTable (Sorted String Table): An immutable on-disk structure that stores key-value pairs in sorted order.
Compaction: A background process that merges SSTables and cleans up tombstones.
The key takeaway here is that the LSM tree trades efficient reads for high write throughput. There is always a trade-off.
I was listening to a very good podcast the other day (it was an AI-related one, but still excellent). It said something like: “No database might have it all. If a database claims they are good at everything, just ask them: at what cost? What’s the trade-off?”
Even in the big CAP theorem, there is a fundamental architectural trade-off. It revolves around choosing between CP (Consistency and Partition Tolerance) and AP (Availability and Partition Tolerance).