Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would someone need an in-memory database?

I read that a few databases can be used in-memory but can't think of reason why someone would want to use this feature. I always use a database to persist data and memory caches for fast access.

like image 381
BrainOverflow Avatar asked Jun 02 '10 05:06

BrainOverflow


People also ask

Why would you use an in-memory database?

The in-memory database defined In-memory data stores are designed to enable minimal response times by eliminating the need to access disks. Because all data is stored and managed exclusively in main memory, in-memory databases risk losing data upon a process or server failure.

What is in-memory database processing and what advantages does it provide?

An in-memory database system streamlines processing by eliminating multiple data transfers, reduces memory consumption by removing multiple copies of data, and simplifies processing by minimizing CPU demands.

What are the disadvantages of in-memory database?

Cons of in-memory databases The use of an RAM means faster access on the one hand, but also brings with it a key disadvantage: the data stored is only temporary. If the computer system should crash, all temporarily-stored data would be lost.


4 Answers

Cache is also a kind of database, like a file system is. 'Memory cache' is just a specific application of an in-memory database and some in-memory databases are specialized as memory caches.

Other uses of in-memory databases have already been included in other answers, but let me enumerate the uses too:

  1. Memory cache. Usually a database system specialized for that use (and probably known as 'a memory cache' rather than 'a database') will be used.
  2. Testing database-related code. In this case often an 'in-memory' mode of some generic database system will be used, but also a dedicated 'in-memory' database may be used to replace other 'on-disk' database for faster testing.
  3. Sophisticated data manipulation. In-memory SQL databases are often used this way. SQL is a great tool for data manipulation and sometimes there is no need to write the data on disk while computing the final result.
  4. Storing of transient runtime state. There are application that need to store their state in some kind of database but do not need to persist that over application restart. Think of some kind of process manager – it needs to keep track of sub-processes running, but that data is only valid as long as the application and the sub-processes run.
like image 195
Jacek Konieczny Avatar answered Nov 05 '22 08:11

Jacek Konieczny


A common use case is to run unit/integration tests.

You don't really care about persisting data between each test run and you want tests to run as quickly as possible (to encourage people to do them often). Hosting a database in process gives you very quick access to the data.

like image 35
Roman Avatar answered Nov 05 '22 09:11

Roman


Does your memory cache have SQL support?

How about you consider the in-memory database as a really clever cache?

That does leave questions of how the in-memory database gets populated and how updated are managed and consistency is preserved across multiple instances.

like image 40
djna Avatar answered Nov 05 '22 10:11

djna


Searching for something among 100000 elements is slow if you don't use tricks like indexes. Those tricks are already implemented in a database engine (be it persistent or in-memory).

A in-memory database might offer a more efficient search feature than what you might be able to implement yourself quickly over self-written structures.

like image 40
Nicolas Raoul Avatar answered Nov 05 '22 10:11

Nicolas Raoul