What Is an In-Memory Database?
- What is an in-memory database?
- What are the advantages of in-memory databases?
- What is the difference between an in-memory database and a traditional disk-based database?
- What are the use cases for in-memory databases?
- How does an in-memory cache work?
- What is the difference between an in-memory cache and an in-memory database?
- What are the limitations of in-memory databases?
- How can AWS support your in-memory database and cache requirements?
What is an in-memory database?
An in-memory database is a purpose-built database that relies primarily on internal memory for data storage, specifically in computer-linked random-access memory (RAM). RAM is the computer’s main memory for performing operations. It enables minimal response times by eliminating the need to access disk drives during computation. In-memory databases are ideal for applications that need microsecond response times or experience traffic spikes to frequently accessed data, such as gaming leaderboards, user session stores, and real-time data analytics. The terms main memory database system, in-memory database system, and real-time database system also refer to in-memory databases.
How does a modern in-memory database work with data tiering?
While traditional in-memory databases relied exclusively on RAM for memory, with periodic saves of the database to disk storage, modern in-memory databases use a "data tiering" approach to memory management. Frequently accessed "hot" data stays in RAM, while "warm" data accessed less frequently automatically moves to high-speed NVMe solid-state drives (SSDs). These fast SSDs are located locally, with optimized data pipelines to enhance speed. This approach provides close to full in-memory performance at a fraction of the cost.
What are the advantages of in-memory databases?
An in-memory database provides several advantages over traditional database management approaches.
Low latency, providing real-time responses
Latency is the lag between the request to access data and the application’s time-to-first-byte response. In-memory databases offer lower latencies by removing the input and output from other storage. They deliver microsecond read latency, single-digit millisecond write latency, and high throughput for local access.
As a result, in-memory storage allows enterprises to perform database operations in near real time. You can design applications that process data and respond to changes near-instantly. For example, in-memory computing of sensor data from self-driving vehicles supports the desired millisecond response time for emergency braking.
High throughput
In-memory databases can support high throughput, depending on RAM size, CPU cores, and bandwidth. Throughput is the number of read (read throughput) or write (write throughput) operations over a given period of time. For example, bytes per minute or transactions per second.
High scalability
With the right planning, you can scale your in-memory database to meet fluctuating application demands. Ensure that the RAM is large enough for future needs, add extra RAM, or use elastic services for growth. Both write and read scaling are possible with minimal performance impacts. The database remains online and supports read and write operations during resizing.
What is the difference between an in-memory database and a traditional disk-based database?
A traditional database does not store its full contents in RAM; instead, it stores the database in external disk drives or solid-state drives, with pieces of data cached in RAM for operations. Every single read/write operation requires disk access to the data stored in the database. Conversely, an in-memory database does store its data in RAM, with supplementary backup to disk. For example, an in-memory database might only save data periodically to external storage media.
What are the use cases for in-memory databases?
In-memory databases are a good choice for use cases requiring fast database data access and low-latency operations. These can include banking, telecommunications, gaming, generative AI, and mobile advertising industries. Here are some example use cases of in-memory databases.
Generative AI and vector search
Vector embeddings are a way to mathematically represent the meaning of abstract concepts so that generative AI models can understand them. They map concepts to coordinates in a massive graph of all language. For example, "running shoes" and "sneakers" would be close together in a cluster on the graph because they’re similar ideas, even though they use different words. Whereas "bank" as in a financial institution and "bank" as in the edge of a river would be far apart, even though they use the same sequence of letters.
AI models can perform "semantic search," or search based on meaning, in milliseconds, because they now have access to vector embeddings via in-memory databases. For example, when a user asks a corporate chatbot a question, the in-memory database instantly retrieves the most relevant company documents to help the AI generate an accurate answer. This is a process known as RAG (Retrieval-Augmented Generation). Using an in-memory database for these applications can speed up inference.
Real-time bidding
Real-time bidding is the buying and selling of online ad impressions. Usually, the bid must be made while the user loads a webpage in 100-120 milliseconds, and sometimes as little as 50 milliseconds. During this period, real-time bidding applications request bids from all buyers for the ad spot, select a winning bid based on multiple criteria, display the offer, and collect post-ad-display information. In-memory databases are ideal for ingesting, processing, and analyzing real-time data with millisecond latency.
Gaming leaderboards
A gaming leaderboard shows a gamer’s position relative to other players of a similar rank. These leaderboards can be highly effective tools for building player engagement. In-memory databases can more quickly deliver sorting results and update the leaderboard in real-time for a game with millions of players.
How does an in-memory cache work?
An in-memory cache uses random-access memory (RAM) to store data, which may include databases, APIs, or other types of data.
Specialized data structures such as hash tables and skip lists allow the indexing of your data records. The indices act as direct pointers to the specific data. When you make an access request, it navigates to the exact data value using the index. Stored data is usually available in a directly usable format.
Technologies and advancements such as 64-bit computing, lower RAM prices, and multi-core servers have made in-memory data storage more common. In addition, a range of cloud-based services allows you to scale your RAM resources up or down as required, making in-memory technology more flexible and accessible.
What is the difference between an in-memory cache and an in-memory database?
In-memory caches provide better performance because writes are not saved to disk, eliminating the extra time needed for data persistence. An in-memory database writes to external storage at certain points, making data changes durable and persistent. This durability comes at the expense of slightly lower performance for writes, unless they are scheduled during times of lower operations. However, in-memory databases still provide far better performance than disk-based databases. From a performance standpoint, the in-memory database sits between an in-memory cache and a traditional database.
What are the limitations of in-memory databases?
Because all data is stored and managed in memory, in-memory databases risk losing data upon a process or server failure. To improve durability, an in-memory database typically saves data to disk periodically.
Historically, the main limitation of in-memory databases was the physical limit of how much RAM you could fit in a server. Now, technologies such as Compute Express Link (CXL) enable networked servers to share memory as a single, massive pool.
Snapshot files
Snapshot files record the database state at a given moment in time. In-memory databases generate snapshots periodically or during a controlled shutdown. Although snapshotting improves durability to some extent, data loss can still occur between snapshots.
Transaction logging
Transaction logging records changes to the database in an external journal file. Logging is independent of data read/write and does not impact performance. The journal file facilitates the automatic recovery of an in-memory database.
Data replication
Some in-memory databases rely on redundancy to provide high availability. They maintain multiple copies of the same data in different memory modules. Module failure triggers automatic failover to the duplicate backup, where the database is loaded in memory. This mitigates the risk of data loss.
How can AWS support your in-memory database and cache requirements?
AWS provides several different fully managed in-memory database and cache services for your specific needs.
Amazon MemoryDB is a durable, in-memory database service that delivers ultra-fast performance. It is compatible with Valkey and Redis OSS, enabling customers to quickly build applications using the same data structures, APIs, and commands they already use today. MemoryDB also supports semantic search to power generative AI.
MemoryDB stores your data durably across multiple Availability Zones (AZs) using a Multi-AZ transactional log to enable fast failover, database recovery, and node restarts.
Amazon ElastiCache is a serverless, fully managed caching service delivering microsecond latency with Valkey-, Memcached-, and Redis OSS-compatibility. ElastiCache Serverless offers zero infrastructure management, zero downtime maintenance, and instant scaling to match any application demand.
Developers can use ElastiCache to scale applications to hundreds of millions of operations per second with microsecond latency and high throughput while reducing costs by caching frequently used data in memory.
Get started with in-memory databases or in-memory caches on AWS by creating a free account today.
Browse all cloud computing concepts
Browse all cloud computing concepts content here:
Did you find what you were looking for today?
Let us know so we can improve the quality of the content on our pages