r/databasedevelopment • • Jun 18 '24

LSM tree "popular" implementations

Looking for implementations of LSM tree that are used in well-known projects either in Go or Rust. C++ or Zig is ok too but prefer any from the first 2. Please comment the link/s below. It may not be separate package, can be an internal one but at least has well defined interface. Thanks!

64 Upvotes

26 comments sorted by

11

u/eatonphil Jun 18 '24

3

u/zer01nt Jun 18 '24

Good stuff. Thanks for all the links @eatonphil!

5

u/AbradolfLinclar Jun 18 '24

Adding one more:

LevelDB uses a LSM tree based engine too.

https://github.com/google/leveldb

1

u/eatonphil Jun 18 '24

Yep that's what RocksDB is based on/a fork of so I considered them to be basically the same.

I'd be curious to learn what the differences are these days since RocksDB forked a while ago...

4

u/DruckerReparateur Jun 18 '24

A lot...

Multithreaded Compaction, Column Families, Ribbon Filters, more compression algorithms, Partitioned Block Index, BlobDB (key-value separation), DeleteRange, SingleDelete, TransactionDB and surely some other stuff

2

u/eatonphil Jun 18 '24

In which direction are you talking about, sorry? And surely they have developed quite a bit in both projects, no?

2

u/DruckerReparateur Jun 18 '24

RocksDB.

LevelDB is in maintenance-only.

2

u/eatonphil Jun 18 '24

Ah thank you. Didn't know.

2

u/raphaelscarv Jun 18 '24

ScyllaDB / Cassandra implement LSM tree too. Interestingly, a new sstable format s adopting an immutable btree for index.

2

u/zer01nt Jun 19 '24

Thanks! I was actually interested in investigating if LSM trees worked as an index them self or require another data structure. Because to me, it seems like it doesn’t but I looked at some comment in Stackoverflow and that argued that it does. I guess your comment answers my ultimate question. 😅

2

u/[deleted] Jun 19 '24

SSTables are sorted by key, but that really only helps with merge, not with binary search (because K/V pairs are variable-length). To do binary search effectively you need to sample every N keys and store their offsets (possibly with key prefixes) in an auxiliary index array.

2

u/raphaelscarv Jun 20 '24

In Cassandra, there's an immutable index for each immutable SSTable data file. You can have a 2-depth index (summary (the sampling of keys) and index itself (set of keys pointing to locations in data file)) or you can also implement an immutable btree-based index, which will go with each SSTable data file too (to get rid of the 2-depth approach).

8

u/eatonphil Jun 18 '24

Here are the docs for TigerBeetle's implementation of an LSM tree in Zig.

https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/about/internals/lsm.md

4

u/[deleted] Jun 18 '24

RocksDB? Used in a lot of modern stuff. Cockroach is in Go

I think TiDB too

7

u/eatonphil Jun 18 '24

Cockroach is in Go

It isn't Cockroach, the database, specifically but Cockroach's Pebble library. https://github.com/cockroachdb/pebble

1

u/[deleted] Jun 18 '24

Oh wow, I didn't know they wrote their own flavor. Good stuff!

3

u/eatonphil Jun 18 '24

TiKV README mentions they use RocksDB

https://github.com/tikv/tikv

3

u/eatonphil Jun 18 '24

Badger in Go is an LSM tree implementation.

https://github.com/dgraph-io/badger

3

u/tech_addictede Jun 19 '24

Here is an LSM implementation in C if you are interested.

https://github.com/CARV-ICS-FORTH/parallax

2

u/1_am_ir0nman Jun 19 '24

You can also checkout Neon database,they have implemented LSM tree structure in rust. https://github.com/neondatabase/neon

1

u/steve_lau Jan 07 '25

Hmm, I think they follow how the Postgres core works, i.e., use the heap storage engine, but a cloud-native version that targets s3, not a LSM.

2

u/1_am_ir0nman Jun 30 '26

sorry back after a long time :) ,AFAIK Neon have a totally separate storage engine called pageserver , Postgres core uses a mutable, in-place heap storage engine that overwrites 8KB blocks on a local disk, a design that cannot work on Amazon S3 because S3 objects are strictly immutable and do not support random in-place writes. Neon solves this by materializing the WALs into pages, and flushing them into immutable delta and image layers using LSM. These immutable layers are then pushed to S3 and continuously does LSM compaction of these layers.

2

u/m_orazow Jun 20 '24

Apache Paimon for lake format for streaming data: https://paimon.apache.org

WiscKey for separating key & value for reduced I/O amplifications. https://www.usenix.org/system/files/conference/fast16/fast16-papers-lu.pdf

1

u/mayreds19 Jun 19 '24

This thread is 🔥