An in-memory database is a purpose-built database that relies primarily on internal memory for data storage. It enables minimal response times by eliminating the need to access standard disk drives (SSDs). In-memory databases are ideal for applications that require microsecond response times or have large spikes in traffic, such as gaming leaderboards, session stores, and real-time data analytics. The terms main memory database (MMDB), in-memory database system (IMDS), and real-time database system (RTDB) also refer to in-memory databases.

What are the advantages of in-memory databases

An in-memory database brings several advantages that we explore in detail below.

Low latency, providing real time responses

Latency is the lag between the request to access data and the application's response. In-memory databases offer predictable low latencies irrespective of scale. They deliver microsecond read latency, single-digit millisecond write latency, and high throughput.

As a result, in-memory storage allows enterprises to make data-based decisions in real-time. You can design applications that process data and respond to changes before it's too late. For example, in-memory computing of sensor data from self-driving vehicles can give the desired split-second response time for emergency braking.

High throughput

In-memory databases are known for their high throughput. Throughput refers to the number of read (read throughput) or write (write throughput) operations over a given period of time. Examples include bytes/minute or transactions per second.

High scalability

You can scale your in-memory database to meet fluctuating application demands. Both write and read scaling is possible without adversely impacting performance. The database stays online and supports read-and-write operations during resizing.

What are the use cases of in-memory databases

In-memory databases are a good choice for banking, telecommunications, gaming, and mobile advertising industries. We give some examples of in-memory database use cases below.

Caching

A cache is a high-speed data storage layer that stores a subset of typically transient data. A cache's primary purpose is to increase data retrieval performance by reducing the need to access the underlying slower storage layer. This means future requests for that data are served up faster than is possible by accessing the data’s primary storage location.

Caching allows you to reuse previously retrieved or computed data efficiently. In-memory data storage works well for faster access to cached data. Caching trades off durability for response time. Response time is faster because data is retrieved from memory, but caching doesn't protect against the loss of data in memory. This is why caching is often used in combination with a disk-based durable database.

Real-time bidding

Real-time bidding refers to 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 sub-millisecond latency.

Gaming leaderboards

A relative gaming leaderboard shows a gamer's position relative to other players of a similar rank. These leaderboards can help build engagement among players and keep gamers from becoming demotivated compared to top players. In-memory databases can 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 relies on random access memory (RAM) to store data. The technology stores data tables directly in the RAM instead of on external drives. Specialized data structures allow the indexing of your data records. The indexes act as direct pointers to specific rows and columns. However, the actual physical data is compressed and non-relational in format. When you make an access request, the database navigates to the exact data value using the index. Stored data is always available in a directly usable format.

Things like 64-bit computing, lower RAM prices, and multi-core servers have made in-memory storage more common. In addition, cloud-based data stores allow you to scale your RAM resources up or down as required, making in-memory technology more flexible and accessible.

Difference between in-memory cache and traditional disk-based databases

A traditional database persists all data to external disk drives or solid-state drives. Every single read-and-write operation requires disk access. Conversely, in-memory cache does not prioritize data persistence. For example, caches may only save data periodically to external storage media. We have summarized the differences between in-memory caches and traditional databases below.

What is the difference between an in-memory cache and an in-memory database

In-memory caches provide better performance because writes are not persisted, eliminating the extra time needed for persisting data. An in-memory database persists writes, making data changes durable. This durability comes at the expense of lower performance for writes. However, in-memory databases still provide better performance than a disk-based database. From a performance standpoint, they sit between an in-memory cache and a disk-based database.

What are the limitations of in-memory caches

Because all data is stored and managed exclusively in memory, in-memory caches risk losing data upon a process or server failure. To improve durability, an in-memory cache may persist data periodically on disk databases. We expand on some mechanisms to improve durability below.

Snapshot files

Snapshot files record the database state at a given moment in time. The in-memory cache generates snapshots periodically or during a controlled shutdown. While snapshotting improves durability to some extent, data loss may 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 cache.

Replication

Some in-memory caches rely on redundancy to provide high availability. They maintain multiple copies of the same data in different memory modules. Module failure results in automatic failover to the duplicate backup copy. This mitigates the risk of data loss with a cache.

How can AWS support your in-memory cache and database requirements

AWS provides several different fully managed in-memory cache and database services for your specific needs.

In-memory database

Amazon MemoryDB for Redis

Amazon MemoryDB for Redis is a durable, in-memory database service that delivers ultra-fast performance. It is compatible with Redis, a popular open-source data store. This enables customers to quickly build applications using the same flexible and friendly Redis data structures, APIs, and commands they already use today. MemoryDB also stores your data durably across multiple Availability Zones (AZs) using a Multi-AZ transactional log to enable fast failover, database recovery, and node restarts.

In-memory caches

Amazon ElastiCache for Redis

Amazon ElastiCache for Redis is a blazing-fast, in-memory caching service that enables microsecond latency to power real-time internet-scale applications. Developers can use ElastiCache for Redis as an in-memory cache, or use cases that don't require high data durability. The ElastiCache for Redis cluster configuration supports customers to run Redis workloads with up to 6.1 TB of in-memory capacity in a single cluster. ElastiCache for Redis also provides the ability to add and remove shards from a running cluster. You can dynamically scale your Redis cluster workloads in and out to adapt to changes in demand.

Amazon ElastiCache for Memcached

Amazon ElastiCache for Memcached is a Memcached-compatible, in-memory, key-value caching service. It delivers the same high performance, ease of use, and simplicity of Memcached. ElastiCache for Memcached is fully managed, scalable, and secure, making it an ideal candidate for use cases where frequently accessed data must be in-memory.

Get started with in-memory caches or databases on AWS by creating a free account today!

Introduction to Amazon MemoryDB for Redis
Introduction to Amazon ElastiCache for Redis