How a Database Really Works Underneath
One question keeps coming up when people start going deeper into databases: How does a database actually work underneath? Not the SQL part. Not the API. Not the dashboard. The real part: Where is t...

Source: DEV Community
One question keeps coming up when people start going deeper into databases: How does a database actually work underneath? Not the SQL part. Not the API. Not the dashboard. The real part: Where is the data actually stored? Is it kept in memory, on disk, or both? How are rows and columns laid out? Why does a query return quickly instead of scanning everything forever? This article is a general answer to that question. Different databases make different tradeoffs, but most serious databases are built from the same small set of ideas. The short answer A database is usually not one magical structure. It is several layers working together: A Storage Format For Data On Disk An In-Memory Layer For Hot Data One Or More Index Structures A Query Engine A Transaction / Recovery Layer When you run a query, the database does not start from scratch. It uses those layers together: find the right pages or files use indexes if they help load needed data into memory execute the query return only the rows