11 Persistence: key-value databases
This chapter covers
- Designing raw key-value database subsystem
- Introducing type-safe interface to the key-value database subsystem
- Designing simple key-value database model
- How to write generic, extensible code with advanced type-level features
It is a rare case for a program to be isolated and have no interactions with any external data storage, whether it’s a relational database, key-value database, filesystem, cloud storage, or something else. While the model of interaction may vary, the idea is always the same: to get access to a significant amount of data that can’t be located directly in the program’s memory.
We’ll be using a new subsystem for the framework, namely the key-value database subsystem. It will be a low-level raw string-based interface in the form of a new Free monadic language, KVDBL, and being a string-based means being unsafe. We’ll then proceed to the next step: enrolling a fully typed and type safe interface on top of the string-based one.
Figure 11.1 Framework subsystems. A new Free monadic language is added into the hierarchy.
I’ll show you how to make the system more correct, robust and convenient. We’ll also talk about extensibility, and in this journey, we’ll learn some useful type-level magic.