Unit 5.5: In-Memory Database (Cache Tier)
Introduction
Two earlier decisions created a gap that this unit closes. Unit 5.3 showed that PostgreSQL standbys do not serve reads, so read capacity must come from somewhere other than more database nodes. Unit 4.3 showed that VM Auto Scaling adds and removes replicas, so sessions and shared state cannot live on any one replica. Both needs point to the same component: a shared in-memory store on the private network.
DBaaS for In-Memory DB is a fully managed key-value in-memory data store based on Valkey and compatible with the Redis OSS API. It suits frequently accessed data that rarely changes, and as a cache it reduces the queries that reach the central database. This unit designs how the application uses it and how the cluster is shaped, then builds FinCorp's cache tier in the DCD.
1. The Cache Tier in the Architecture
1.1 Two Jobs, One Store
The cache tier does two different jobs. As a read cache, it holds results the database would otherwise compute again: product catalogues, customer profile views, reference data. Losing it costs performance, not correctness. As a state store, it holds session data and shared counters for the compute tier. Losing it logs users out or resets state. The two jobs need different persistence and eviction settings, so decide per key family which job it serves.
1.2 Cache-Aside or Write-Through
The application, not the platform, decides how the cache and the database stay consistent.
| Pattern | How it works | Advantages | Disadvantages | Best for |
|---|---|---|---|---|
| Cache-aside | The application reads the cache; on a miss it reads PostgreSQL and writes the result to the cache with a time to live (TTL) | Only requested data is cached; a cache outage degrades to database reads | First read after a change or expiry is slow; stale data until the TTL ends or the key is deleted | Read-heavy data that tolerates short staleness |
| Write-through | The application writes to PostgreSQL and then updates or deletes the cache key in the same code path | Cache stays current for written keys | Every write pays two round trips; a failed cache update must be handled | Data read immediately after it is written |
FinCorp uses cache-aside with TTLs for catalogue and profile views, and deletes the profile key in the same code path that writes the profile, so a customer never sees their own change late. The database stays the system of record in both patterns.
1.3 Placement on the Private Network
DBaaS clusters connect only to private networks, and an In-Memory DB cluster has one network connection to one LAN of a VDC. FinCorp places it on fc-data next to PostgreSQL, where the portal servers already have a second NIC (Unit 5.3), so the cache adds no new network path. Clients connect through the cluster's DNS name, which points to the primary instance. Communication is secured with TLS when the client uses it; the certificate authority is Let's Encrypt.
2. Shaping the Cluster
2.1 Instances and Failover
A cluster has 1 to 5 instances: one creates a standalone instance, and 2 to 5 create one primary with passive secondaries. Replication is always asynchronous, so a failover can lose writes that only the primary had. The secondaries are passive: like PostgreSQL standbys, they add availability, not read throughput, so read capacity comes from the primary's cores and RAM. IONOS CLOUD recommends a minimum of three instances for production.
Failover is automatic: when the primary fails, a replica is promoted. There is no Sentinel; during a planned switchover the IP address of the primary moves to the promoted replica, and the server closes the TCP connection so that the client reconnects. Use a client library that reconnects on its own, and treat a short burst of cache misses after a failover as normal.
A maintenance window is mandatory. During it, short, occasional downtime can occur. The window is your start time plus four hours; if you set none, maintenance can happen any time Monday to Friday between 7 AM and 5 PM.
2.2 Persistence
The persistence mode decides what survives a restart:
| Mode | Behaviour | Storage derived |
|---|---|---|
| In-Memory | Data is in memory only and not persisted | 1 x RAM |
| AOF (Append Only File) | Every write operation is logged | 2 x RAM |
| RDB | Periodic point-in-time snapshots of the in-memory state | 2 x RAM |
| RDB and AOF | Both mechanisms active | 4 x RAM |
With the default RDB settings, a snapshot is written every hour after a single change, every five minutes after at least 100 writes, and every minute after at least 10,000 writes; data written since the last snapshot can be lost. A pure read cache can run In-Memory, because the database can refill it. A state store needs AOF or RDB and AOF. Block storage follows from RAM and persistence; it cannot be set manually and cannot be downsized.
2.3 Eviction and Sizing
When memory reaches its limit, the eviction policy decides what happens: noeviction, allkeys-lru, allkeys-lfu, allkeys-random, volatile-lru, volatile-lfu, volatile-random or volatile-ttl. The allkeys-* policies may evict any key, which suits a pure cache. The volatile-* policies evict only keys that have an expiry set, which protects keys without one. noeviction rejects new writes instead.
An instance has between 1 and 62 dedicated CPU cores and between 4 and 240 GB of RAM, within your quota. RAM cannot be downgraded after the cluster is created, so start from a measured working set plus headroom and grow, rather than starting large.
FinCorp's settings follow from Section 1.1. Cache entries carry a TTL; session entries carry none and are removed by the portal at logout and by its session sweeper. With volatile-lru, memory pressure evicts cache entries first and never a session. AOF persistence keeps sessions across a restart.
2.4 Snapshots and Restore
Snapshots go to an Object Storage location you choose, at one or more hours of the day (UTC), with retention between 1 and 365 days and a default of 7. A restore uses the nearest snapshot taken at or before the chosen time: there is no continuous point-in-time recovery. Only snapshots from clusters in the same region can be restored. For a cache, snapshots are rarely restored; for a state store, they bound what a disaster loses.
DCD Implementation Walkthrough
You will create FinCorp's cache and session tier fc-imdb-portal on fc-data in fc-prod-fra-core, with three instances, AOF persistence and volatile-lru eviction, then point the portal at it. This realises the read layer of Section 1 and the settings of Section 2.
Prerequisites: the VDC fc-prod-fra-core with the fc-data LAN and at least one VM on it; an account with the Access and manage DBaaS privilege; the address .3 on fc-data reserved for the cluster; the PostgreSQL cluster fc-pg-portal from Unit 5.3.
Build goal: Provision the cache and wire it as a read-through layer.
Steps (in the Data Center Designer):
- Go to Menu > Databases > In-Memory DB and select Create cluster.
- In Properties, enter the Cluster name
fc-imdb-portaland select the Frankfurt Location. The location cannot be changed after creation. - In Cluster configuration, select the Version and enter
3Instances. Replication Type shows Asynchronous and CPU Type shows Dedicated Core. - Set Persistence to AOF (Append Only File) and Eviction Policy to
volatile-lru. - In Snapshot, select an Object Storage Location outside Frankfurt, a Retention days value, and at least one Snapshot Hours entry outside peak traffic.
- In Instance configuration, set the Number of CPUs and the RAM Size per instance from the measured working set. RAM cannot be reduced later.
- In Network configuration, select
fc-prod-fra-core, thefc-dataVDC LAN, and enter the.3address in CIDR notation as the Private IP address. - In Maintenance Period, select a Day and a Start Time (UTC). Do not leave it empty.
- In User Creation, enter the Username and Password for the portal's service identity.
- Select Save. When the state is Available, copy the DNS name from the cluster details.
- In the portal configuration, set the cache endpoint to that DNS name with TLS, set TTLs on catalogue and profile keys, and implement the cache-aside read path and the key deletion in the profile write path.
Common mistakes:
- Sending reads to the secondaries. They are passive; scale the primary instead.
- Using
allkeys-lrufor a store that also holds sessions. Memory pressure then logs users out. - Running a session store with In-Memory persistence. A restart loses every session.
- Starting with a large RAM size "to be safe". RAM cannot be downgraded.
- Leaving the maintenance window empty. Maintenance can then fall in business hours.
Summary
The cache tier is what makes the no-read-replica pattern and safe auto-scaling work: the database stays the system of record, In-Memory DB serves repeated reads and holds shared state. Decide per key family whether it is cache or state, then set persistence and eviction to match. Secondaries are passive and asynchronous, RAM only grows, and restores come from snapshots rather than continuous recovery.
Key Points:
- In-Memory DB is private-only, with one LAN connection, reached through the primary's DNS name.
- Clusters have 1 to 5 instances; secondaries are passive and replication is asynchronous.
- Persistence modes set the derived storage from 1 x to 4 x RAM; storage and RAM cannot be downsized.
volatile-*eviction protects keys without an expiry;allkeys-*suits a pure cache.- Restores use the nearest preceding snapshot; there is no continuous point-in-time recovery.
Important Terminology:
- Cache-aside: a pattern in which the application fills the cache on a miss and the cache never talks to the database.
- Write-through: a pattern in which every database write also updates or deletes the cache key.
- Eviction policy: the rule that decides which keys are removed when memory is full.