Choosing the Right Engine For Your Database

Table of Contents

About

Database engines are the underlying software that run different databases we use in our day to day lives as software engineers. It is important for us to be aware of different flavors these databases come in and different use cases that each have.

This post will cover two of the most widely used types of database engines, draw comparison between them, and try to cover the best uses cases for each of them.

Database Engine Types

LSM Tree Engines

LSM Tree or Log-Structured Merge-Tree Storage Engine are segmented append-only files which are used to store data. In order to retrieve data the most recent segment is searched and traversed backwards to previous segments. an O(N) is needed to find a record that is required and due to this indexes are mostly used to speed up the data retrieval I’m process.

An important process used in LSM Tree Engines in the process of compaction where by log files are combined and only the latest data is kept. Compactions are usually done in a background thread where merging of two log files occurs.

B-Trees

In B-Trees the data is stored in a fixed sized key-value pair blocks. each value can be a pointer to another block, you can think of these blocks as intermediary which will help to retrieving the data block.

B-Trees also tend to have write-ahead logs which are protection against system failures. Usually, operations are first written to this log to protect the data in case of system or database failures.

Database Engines Comparisons

As mentioned in the above points, B-Trees tend to perform at least two write operations, once to the write-ahead log and another to the tree itself. Compared to LSM Tree engines B-Trees tend to perform worse in a write heavy environment

On the other side LSM Trees can also interfere with write and read operations during the compaction process. For example in case of excessive disk I/O no request can be responded to until the completion of the compaction process. This combined with the inconsistency of these operations means that compared to B-Trees, LSM trees tend to perform in a much more unpredictable manner.

Another point worth mentioning is that B-Trees always store a single copy of each key memory while LSM Tree can have the same keys stored in different segments.

Database Engine use cases

In conclusion LSM Trees tend to perform much better in a write heavy environment due the fact that write operation being append only while B-Trees are better performing in a read heavy environment.

Tags :

Related Posts

Getting to know a new codebase can feel overwhelming, but it’s a skill you can master with the right approach. In this post, I’ll share insights on how to break down and familiarize yourself with any codebase

Read More

Balancing task delivery and team growth is key for a team leader. This blog posts discussed approaches to builds confidence and problem-solving skills while not jeopardizing project deadlines.

Read More

Unlock your potential with the Structured Ambition Framework. This guide shows you how to transform big dreams into actionable plans using Obsidian, helping you set yearly visions, break them down into manageable tasks, and maintain consistency through journaling and reflection.

Read More