Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
7
7390memorywave-guide
  • Project
    • Project
    • Details
    • Activity
    • Cycle Analytics
  • Issues 43
    • Issues 43
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Create a new issue
  • Jobs
  • Issue Boards
  • Alejandra Ulrich
  • 7390memorywave-guide
  • Issues
  • #3

Closed
Open
Opened Oct 17, 2025 by Alejandra Ulrich@alejandraulric
  • Report abuse
  • New issue
Report abuse New issue

What an In-memory Database is and the Way It Persists Data Efficiently


In all probability you’ve heard about in-memory databases. To make the long story brief, an in-memory database is a database that retains the whole dataset in RAM. What does that imply? It means that every time you question a database or update knowledge in a database, you solely entry the primary memory. So, there’s no disk concerned into these operations. And this is nice, because the principle memory is method faster than any disk. A good example of such a database is Memcached. However wait a minute, how would you get better your data after a machine with an in-memory database reboots or crashes? Properly, with just an in-memory database, there’s no way out. A machine is down - the data is misplaced. Is it doable to mix the facility of in-memory information storage and the durability of good old databases like MySQL or Postgres? Certain! Wouldn't it have an effect on the efficiency? Here come in-memory databases with persistence like Redis, Aerospike, Tarantool. You may ask: how can in-Memory Wave storage be persistent?


The trick here is that you still keep every thing in memory, however moreover you persist every operation on disk in a transaction log. The first thing that you could be discover is that though your fast and nice in-memory database has received persistence now, queries don’t slow down, because they nonetheless hit solely the principle memory like they did with simply an in-memory database. Transactions are utilized to the transaction log in an append-solely manner. What's so good about that? When addressed on this append-solely manner, disks are fairly fast. If we’re talking about spinning magnetic exhausting disk drives (HDD), they will write to the top of a file as quick as 100 Mbytes per second. So, Memory Wave Workshop magnetic disks are fairly quick when you utilize them sequentially. However, they’re completely slow when you utilize them randomly. They will usually complete round a hundred random operations per second. If you happen to write byte-by-byte, every byte put in a random place of an HDD, you can see some real 100 bytes per second as the peak throughput of the disk on this scenario.


Once more, it's as little as a hundred bytes per second! This tremendous 6-order-of-magnitude difference between the worst case situation (one hundred bytes per second) and Memory Wave the perfect case scenario (100,000,000 bytes per second) of disk entry pace is based on the truth that, so as to hunt a random sector on disk, a bodily movement of a disk head has occurred, when you don’t want it for sequential access as you just learn data from disk because it spins, with a disk head being stable. If we consider solid-state drives (SSD), then the state of affairs will be better due to no moving elements. So, what our in-memory database does is it floods the disk with transactions as quick as 100 Mbytes per second. Is that quick enough? Nicely, that’s actual quick. Say, if a transaction dimension is 100 bytes, then this will be one million transactions per second! This quantity is so excessive that you can positively be sure that the disk won't ever be a bottleneck in your in-memory database.


1. In-memory databases don’t use disk for non-change operations. 2. In-memory databases do use disk for knowledge change operations, but they use it in the fastest possible means. Why wouldn’t regular disk-based mostly databases undertake the identical methods? Well, first, not like in-memory databases, they should learn information from disk on each query (let’s overlook about caching for a minute, this goes to be a subject for an additional article). You never know what the next query can be, so you can consider that queries generate random entry workload on a disk, which is, remember, the worst situation of disk utilization. Second, disk-based mostly databases need to persist adjustments in such a means that the modified data may very well be immediately learn. Unlike in-memory databases, which normally don’t read from disk except for recovery causes on beginning up. So, disk-based mostly databases require particular data constructions to keep away from a full scan of a transaction log as a way to learn from a dataset fast.


These are InnoDB by MySQL or Postgres storage engine. There can be another data structure that is somewhat higher in terms of write workload - LSM tree. This trendy knowledge construction doesn’t solve problems with random reads, but it partially solves issues with random writes. Examples of such engines are RocksDB, LevelDB or Vinyl. So, in-memory databases with persistence can be real quick on both read/write operations. I imply, as fast as pure in-Memory Wave Workshop databases, utilizing a disk extraordinarily effectively and never making it a bottleneck. The last however not least matter that I want to partially cover right here is snapshotting. Snapshotting is the best way transaction logs are compacted. A snapshot of a database state is a duplicate of the entire dataset. A snapshot and latest transaction logs are enough to get better your database state. So, having a snapshot, you may delete all the outdated transaction logs that don’t have any new information on high of the snapshot. Why would we have to compact logs? Because the more transaction logs, the longer the recovery time for a database. Another cause for that is that you wouldn’t need to fill your disks with outdated and ineffective information (to be perfectly sincere, previous logs generally save the day, but let’s make it one other article). Snapshotting is actually as soon as-in-a-while dumping of the entire database from the main memory to disk. As soon as we dump a database to disk, we will delete all the transaction logs that do not contain transactions newer than the final transaction checkpointed in a snapshot. Easy, right? This is just because all different transactions from the day one are already thought-about in a snapshot. You might ask me now: how can we save a constant state of a database to disk, and the way will we decide the most recent checkpointed transaction whereas new transactions keep coming? Well, see you in the next article.

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
No due date
0
Labels
None
Assign labels
  • View project labels
Reference: alejandraulric/7390memorywave-guide#3