A Deep Dive into How Distributed Data Systems Work
Alex Petrov

#Data
#Database
#software_developers
#software_engineers
#software_architects
#Distributed_systems
در انتخاب، استفاده و نگهداری از پایگاه داده، درک سازوکارهای درونی آن امری ضروری است. اما با وجود تعداد زیادی از پایگاههای داده توزیعشده و ابزارهای مختلف امروزی، فهم اینکه هر یک چه ویژگیهایی ارائه میدهند و چه تفاوتهایی دارند، اغلب دشوار است. در این راهنمای کاربردی، «الکس پتروف» توسعهدهندگان را با مفاهیم مربوط به معماری داخلی پایگاههای داده و موتورهای ذخیرهسازی مدرن آشنا میکند.
در سراسر این کتاب، مطالبی برگرفته از کتابها، مقالات علمی، پستهای وبلاگی و کد منبع چند پایگاه داده متنباز بررسی میشود. این منابع در پایان بخشهای اول و دوم فهرست شدهاند. خواهید دید که تفاوتهای اصلی میان بسیاری از پایگاههای داده مدرن در زیربخشهایی نهفته است که نحوه سازماندهی ذخیرهسازی و چگونگی توزیع دادهها را تعیین میکنند.
در گفتگوهای فنی در کنفرانسها اغلب یک سؤال تکراری مطرح میشود:
«چطور میتوانم بیشتر درباره ساختار درونی پایگاههای داده یاد بگیرم؟ حتی نمیدانم از کجا شروع کنم.»
اغلب کتابهایی که در زمینه سیستمهای پایگاه داده نوشته شدهاند، به جزئیات پیادهسازی موتور ذخیرهسازی نمیپردازند و روشهای دسترسی مانند B-Treeها را تنها بهصورت سطحی شرح میدهند. تعداد کمی از کتابها به مفاهیم جدیدتر مانند انواع مختلف B-Tree یا ذخیرهسازی لاگساختار پرداختهاند، بنابراین معمولاً توصیه میشود که مقالات علمی مطالعه شود.
اما همه میدانند مطالعه مقالات کار آسانی نیست: اغلب فاقد زمینهسازی مناسب هستند، بیانشان ممکن است مبهم باشد، ارتباط میان آنها اندک است و پیدا کردنشان دشوار. این کتاب خلاصههایی دقیق از مفاهیم مهم در سیستمهای پایگاه داده ارائه میدهد و میتواند راهنمایی برای علاقهمندان به یادگیری عمیقتر باشد یا بهعنوان یک برگه تقلب برای کسانی که با این مفاهیم آشنایی دارند، عمل کند.
هدف این کتاب فقط توسعهدهندگان پایگاه داده نیست. بلکه برای همه افرادی مناسب است که نرمافزاری میسازند که از پایگاه دادهها استفاده میکند: توسعهدهندگان نرمافزار، مهندسان پایداری (SREها)، معماران نرمافزار و مدیران فنی.
اگر زیرساختهای فنی سازمان شما – خواه پایگاه داده، صف پیام، پلتفرم کانتینری یا زمانبندیکننده وظایف – بخش حیاتی محصولتان باشد، لازم است تغییرات پروژهها، لاگها و لیستهای پستی را دنبال کنید تا با جامعه و جدیدترین تحولات آنها همگام بمانید.
آشنایی با اصطلاحات و درک ساختار درونی سیستمها، به شما کمک میکند از این منابع اطلاعاتی بهتر استفاده کرده، ابزارهایتان را بهکار گیرید، و مشکلات و گلوگاههای احتمالی را بهتر شناسایی و رفع کنید. در مواقع بروز مشکل، داشتن دیدی کلی نسبت به نحوه عملکرد سیستمهای پایگاه داده، به شما امکان میدهد یک فرضیه بسازید، آن را آزمایش کنید، علت اصلی را پیدا کنید و برای دیگر نگهداران پروژه توضیح دهید.
این کتاب همچنین برای ذهنهای کنجکاو است؛ کسانی که از سر علاقه و بدون نیاز فوری، به یادگیری میپردازند: افرادی که اوقات فراغت خود را صرف ساختن کامپایلر، نوشتن سیستمعامل خانگی، ویرایشگر متن، بازیهای کامپیوتری، یادگیری زبانهای برنامهنویسی و دریافت اطلاعات تازه میکنند.
برای مطالعه این کتاب، فرض بر آن است که خواننده تجربهای اولیه در توسعه سیستمهای سمت سرور (Backend) و کار با پایگاههای داده بهعنوان کاربر دارد. آشنایی با ساختارهای داده، در درک سریعتر مطالب مفید خواهد بود.
When it comes to choosing, using, and maintaining a database, understanding its internals is essential. But with so many distributed databases and tools available today, it’s often difficult to understand what each one offers and how they differ. With this practical guide, Alex Petrov guides developers through the concepts behind modern database and storage engine internals.
Throughout the book, you’ll explore relevant material gleaned from numerous books, papers, blog posts, and the source code of several open source databases. These resources are listed at the end of parts one and two. You’ll discover that the most significant distinctions among many modern databases reside in subsystems that determine how storage is organized and how data is distributed.
This book examines:
• Storage engines: Explore storage classification and taxonomy, and dive into B-Tree-based and immutable Log Structured storage engines, with differences and use-cases for each
• Storage building blocks: Learn how database files are organized to build efficient storage, using auxiliary data structures such as Page Cache, Buffer Pool and Write-Ahead Log
• Distributed systems: Learn step-by-step how nodes and processes connect and build complex communication patterns
• Database clusters: Which consistency models are commonly used by modern databases and how distributed storage systems achieve consistency
Table of Contents
Part I. Storage Engines
1. Introduction and Overview
2. B-Tree Basics
3. File Formats
4. Implementing B-Trees
5. Transaction Processing and Recovery
6. B-Tree Variants
7. Log-Structured Storage
Part I Conclusion
Part II. Distributed Systems
8. Introduction and Overview
9. Failure Detection
10. Leader Election
11. Replication and Consistency
12. Anti-Entropy and Dissemination
13. Distributed Transactions
14. Consensus
Part II Conclusion
Who is this book for?
In conversations at technical conferences, I often hear the same question: “How can I learn more about database internals? I don’t even know where to start.” Most of the books on database systems do not go into details of storage engine implementation, and cover the access methods, such as B-Trees, on a rather high level. There are very few books that cover more recent concepts, such as different B-Tree variants and log-structured storage, so I usually recommend reading papers.
Everyone who reads papers knows that it’s not that easy: you often lack context, the wording might be ambiguous, there’s little or no connection between papers, and they’re hard to find. This book contains concise summaries of important database systems concepts and can serve as a guide for those who’d like to dig in deeper, or as a cheat sheet for those already familiar with these concepts.
Not everyone wants to become a database developer, but this book will help people who build software that uses database systems: software developers, reliability engineers, architects, and engineering managers.
If your company depends on any infrastructure component, be it a database, a messaging queue, a container platform, or a task scheduler, you have to read the project change-logs and mailing lists to stay in touch with the community and be up-to-date with the most recent happenings in the project.
Understanding terminology and knowing what’s inside will enable you to yield more information from these sources and use your tools more productively to troubleshoot, identify, and avoid potential risks and bottlenecks. Having an overview and a general understanding of how database systems work will help in case something goes wrong. Using this knowledge, you’ll be able to form a hypothesis, validate it, find the root cause, and present it to other project maintainers.
This book is also for curious minds: for the people who like learning things without immediate necessity, those who spend their free time hacking on something fun, creating compilers, writing homegrown operating systems, text editors, computer games, learning programming languages, and absorbing new information.
The reader is assumed to have some experience with developing backend systems and working with database systems as a user. Having some prior knowledge of different data structures will help to digest material faster.
About the Author
Alex is a data infrastructure engineer, database and storage systems enthusiast, Apache Cassandra committer and PMC member, interested in storage, distributed systems and algorithms.









