Menu

Serialization and Deserialization in Database Engines: How Data Becomes Bytes
πŸ“°

Serialization and Deserialization in Database Engines: How Data Becomes Bytes

DEV Community: databaseΒ·Farhad Rahimi KlieΒ·about 3 hours ago
#7aCNrGrY
#devtodatabase#devto#dev#include#define
Reading 0:00
15s threshold

When building a database engine from scratch, one of the most important concepts you need to understand is serialization and deserialization .

You might be wondering:

How does a database store data on disk?

How does it convert a C structure into bytes?

How does it read those bytes back into memory?

How can we save records and retrieve them after restarting the database?

These questions lead us to two fundamental concepts: serialization and deserialization.

Let's understand how they work and how we can implement them in C.

1. What Is Serialization?

Serialization is the process of converting data structures in memory into a format that can be stored or transmitted.

For example, imagine we have the following C structure:

typedef struct { int id ; char name [ 32 ] ; int age ; } User ;

Enter fullscreen mode

Exit fullscreen mode

We can create a user:

User user = { . id = 1 , . name = "Farhad" , .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.