Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Beyond Cache: The Persistence Problem

Configure native persistence on the cache, kill the cluster, restart, and watch every entry come back. The cluster becomes the durable store, with no separate database.

Introduction

In Cache-Aside Under Load, MariaDB held the truth and the cache absorbed read pressure. Production ran two systems, and the cache could be wiped at any moment without losing data.

This tutorial inverts that arrangement. Native persistence makes the cache itself the durable store. Configure persistence on the data region, load 10 customers, stop the cluster, start it again, and read all 10 customers back. There is no parent database.

Native persistence answers a recovery problem that snapshot-based stores cannot solve cleanly. A periodic snapshot leaves a window between writes, and whatever happened in that window is gone after a crash. An append-only command log captures every write but grows without bound. The production answer in those systems is to pair the cache with a SQL store, or accept the recovery semantics.

Native persistence is page-level. Every write hits the Write-Ahead Log before the in-memory page changes, and periodic checkpoints flush dirty pages to disk. On restart, the cluster loads the latest checkpoint and replays the WAL forward. Recovery is WAL replay time, not snapshot interval.

This is the only tutorial in the path that changes the cluster image. Persistence is configured at startup. The engine does not support flipping the flag on a running cluster. You build a parallel cache-cluster-persistent/ and a parallel Maven project alongside the in-memory ones from the rest of the path.

Prerequisites

  • Completion of Cache-Aside Under Load. That tutorial established the cache-as-accelerator architecture this tutorial inverts.

  • Docker Compose 2.23 or later.

  • Java 17 or later for the client runtime.

  • Maven 3.6 or later.

  • No other GridGain 8 cluster running on ports 47500, 47100, or 10800. This tutorial uses the same port assignment as the rest of the path. Stop any cluster on those ports before starting the one this tutorial creates.

This tutorial creates a fresh cache-cluster-persistent/ directory and a fresh native-persistence/ Maven project. The cache-cluster/ and previous Maven projects from the path stay where they are. Nothing is modified.

What You Will Learn

  • How a single boolean flag on the data region turns the cache into a durable store

  • Why a fresh persistent cluster starts INACTIVE and what activation actually does

  • What baseline topology pins and how the cluster auto-activates when the full baseline rejoins

  • Where on disk the cache, the WAL, and the checkpoint files live, and what they look like after a restart

  • When native persistence is the right answer and when CacheStore write-through still fits

What You Will Build

A single-node persistent GridGain cluster running in Docker, configured with the data region's persistenceEnabled flag turned on. A small Maven project with three programs: one to activate the cluster and report the baseline, one to seed 10 customer rows, and one to verify those rows survive a stop and start of the container.

By the end, you will have stopped the cluster, started it again, and watched every entry the cache held before the stop come back without any reload from an external source.

Configure the Persistent Cluster

The persistent cluster runs on the same image as the in-memory cluster from the path. The change is the configuration: a dataStorageConfiguration block that turns on persistenceEnabled for the default data region and points the WAL at a writable directory. The data region is the cluster's memory-and-disk topology unit. Caches reside in regions, and persistence is regional, not per-cache. One flag, one place, every cache that lands in this region inherits durability.

Create a cache-cluster-persistent/ directory in your working tree. The two files below ship inline in this tutorial. Copy each into the new directory.

cache-cluster-persistent/docker-compose.yml

The GridGain 8 compose pins user: "0" so the container can write to the named volumes. Without it the container's default user (uid=10000) cannot create the per-node directories the WAL writer needs. The compose also mounts the same enterprise license file the rest of the path uses. Native persistence is included in GridGain 8 Enterprise with the standard license, no per-feature configuration required.

cache-cluster-persistent/ignite-config-persistent.xml

The four blocks each have a job. dataStorageConfiguration declares the persistent region and points the WAL at the /wal mount. discoverySpi and communicationSpi pin the discovery and communication ports so the host JVM client knows exactly where to connect. addressResolver rewrites the container's announced hostname (node1) to 127.0.0.1. Without that rewrite, the server would tell the client to talk to its container-internal address (172.18.0.2), which the host JVM cannot reach.

GridGain 8 needs one more file. Copy the same gridgain-license.xml from the rest of the path into cache-cluster-persistent/.

Start the cluster.

Read the startup logs and confirm the persistent default region was declared.

Expected output:

Two things matter in this output. The default region has persistence=true, which means any cache that lands in the default region is backed by disk. The cluster is also INACTIVE. You have to activate it explicitly before the cache accepts writes.

Activate the Cluster

Persistent clusters start INACTIVE on first start. Activation is explicit and one-time per cluster lifecycle. Once activated, the cluster persists the activation decision across restarts. On subsequent starts the cluster auto-activates when all baseline nodes rejoin.

Create a fresh Maven project alongside cache-cluster-persistent/.

native-persistence/pom.xml

GridGain 8 artifacts are not on Maven Central. The <repositories> block points Maven at the GridGain external Nexus.

The model class is a plain POJO. The lesson is durability, not schema.

The first program connects a thick client to the cluster, prints the current state, activates the cluster if it is INACTIVE, and reports the baseline.

Run the program. Compile first because exec:exec does not trigger compilation on its own.

Expected output:

The consistentId value differs on your machine. The rest is identical.

Seed and Verify

Add a second class that creates the Customer cache and loads 10 rows. The cache API is the same as it was in the in-memory tutorials; persistence is invisible at the application level, so the calls below look like ordinary cache.put operations.

Create this file alongside PersistenceConfig.java and Customer.java. It is a separate public static void main, runnable independently.

Run it.

Expected output:

The cache is now durable. Every put hit the WAL before the in-memory page changed. The next step proves it.

Kill, Restart, Verify

Stop the container. docker compose stop halts the running node without removing the container or the volumes. The data files stay on disk where they are.

Confirm the volumes survived.

Expected output:

Start the container again. The same image picks up the same files.

Read the post-start logs. The cluster comes back up INACTIVE for a fraction of a second, then auto-activates because all baseline nodes are online.

Expected output:

The ^-- Baseline [id=0, size=1, online=1, offline=0] line is the cluster reading its persisted baseline from disk. The cluster recognizes the single node it expected, sees that node has rejoined, and activates without a manual call. Multi-node clusters work the same way once every baseline node has rejoined. If a node is missing, the cluster waits.

Run the third program. It connects, reads the state, and reads every customer back from the cache.

Expected output:

The cache survived. No reload from a database, no cache warm step. The cluster came back up and the data was already there.

Look at what is on disk. The next commands inspect the data and WAL directories from inside the container.

Expected output:

The node00-<consistentId>/ directory is the per-node persistent state. Look inside it.

Expected output:

cache-Customer/ is the directory for the cache the seed program created. cp/ is the checkpoint directory. The cluster writes a checkpoint binary every few minutes by default. metastorage/ holds cluster-wide configuration. Inspect the cache directory.

Expected output:

Three artifact types make up the cache directory:

  • cache_data.dat: cache metadata (configuration, types, indexes declared on the cache).

  • index.bin: the cache's indexes.

  • part-N.bin: one partition's data per file. The cluster preallocates each partition file at 45KB regardless of how many rows it holds.

With 10 customers spread across 10 partitions, every partition file has roughly one row in it.

The WAL lives on the second volume.

Expected output:

10 active WAL segments, each preallocated at 64MB. The WAL is sparse-allocated, so the apparent size overstates the actual disk consumption. The archive directory is empty:

Expected output:

The archive fills only when the active WAL rotates. With 10 customer puts the active segment never filled, so nothing rotated. On a busy cluster the archive grows and the cluster trims it according to maxWalArchiveSize.

The diagram below shows the lifecycle these files participate in: every write hits the WAL, periodic checkpoints flush dirty pages to disk, and on restart the cluster loads the latest checkpoint and replays the WAL forward from that point.

Going Further: Multi-Node Persistence

Single-node persistence proves the durability story cleanly. Multi-node persistence introduces a second concern. The baseline expects every node it activated with. If a baseline node is missing on restart, the cluster does not auto-activate. The operator either waits for the missing node to rejoin, removes it from the baseline manually, or enables auto-adjust mode (cluster().baselineAutoAdjustEnabled(AutoAdjustMode.SCALE_UP, true) for scale-up only; the single-argument baselineAutoAdjustEnabled(boolean) is deprecated) so the cluster reshapes the baseline as nodes join and leave.

Multi-node persistence deserves its own guide. Until that guide ships, the official docs cover the failure modes in detail at Baseline Topology.

Summary

Two takeaways carry forward.

Persistence is one boolean on the data region, and the application code does not change. The Customer cache reads and writes the same way it would on an in-memory cluster. What changes is the operational lifecycle: persistent clusters have state, have baseline topology, and produce on-disk artifacts that survive process death.

Recovery is page-level, not snapshot-level. Every write hits the WAL before the in-memory page is updated. On restart, the cluster loads the latest checkpoint and replays the WAL forward. The recovery window is WAL replay time, not snapshot interval.

The deeper reframing is architectural. Cache-aside paired the cache with a database because the cache was volatile. Native persistence collapses the two roles. The application talks to one system, and that system handles speed and durability together. For evaluators considering removing a relational database from a hot path, this is the proof-of-concept tutorial.

Three topics belong in adjacent content, each its own guide:

  • Multi-node baseline mechanics, including auto-adjust and recovery from missing baseline nodes.

  • Data region sizing and setMaxSize tuning.

  • Snapshot APIs (the GridGain snapshot facade, ignite.plugin(GridGain.PLUGIN_NAME).snapshot()) for point-in-time backups, useful when the recovery model needs a coarser granularity than WAL replay.

Stop the cluster cleanly when finished:

Use down -v instead of down if you want to remove the named volumes. Keeping the volumes preserves the data for the next time you restart the cluster.

What's Next

The next tutorial in the path, Distributed Primitives: The Coordination Problem, takes the cluster past storage and shows it as a coordination layer: distributed locks, atomic counters, and queues that span the cluster.

  • Cache-Aside Under Load is the architecture this tutorial inverts. The cache acts as a read-through accelerator while MariaDB holds the truth.

  • Compute Where the Data Lives shows another way the cluster grows beyond a key-value store: by running Java on the nodes that own the data.

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?