Replacing embedded Raft with Valkey in a configuration service

A configuration service that embedded its own Raft: which responsibilities stayed in the service when Valkey replaced it, and why every multi-key write then became an atomic script.

November 20263 min readPlatformsSecuritySecrets and configuration authority

Scraped chalk with faint slate ridges fills the upper left above one confident sweep of terracotta and near-black, edged with pale gold.
On this page
  1. Separating service logic from storage
  2. Keeping multi-key writes atomic
  3. Handling concurrent writers
  4. Durability after Raft

Embed Raft inside an application service and sooner or later you are maintaining a distributed datastore that happens to serve an API on the side.

Owning consensus inside an application only makes sense when the domain cannot be separated from how state is replicated. For a configuration service, the two are largely independent. Ours is a backend service that stores shared key-value configuration, including policies and credentials, which agents and the services that connect them to other systems read, write, and watch over REST and WebSocket. It carried its own Raft implementation inside the application until I replaced that consensus stack with Valkey, an open-source in-memory data store forked from Redis. A service like this should keep only the responsibilities that depend on what a value means or who is asking and hand the rest to a store. Moving off a replicated log, though, means deliberately rebuilding on that store a property nobody asks for by name: every change applied in one order to one state machine.

Separating service logic from storage

Previously, the service was both a configuration API and a consensus cluster. The application handled its own Raft log, leader election, peer discovery, follower-to-leader write proxying, and snapshot shipping. Raft itself was not the problem, and this was a serious implementation backed by adversarial tests. Still, maintaining that layer meant spending engineering time on consensus invariants unrelated to configuration, such as ensuring followers ran their log-consistency check even on empty heartbeats so a diverged follower could not cause an inflated matchIndex on the leader.

Deciding what to keep and what to hand off came down to a simple boundary: anything that depends on what a value means or who is asking belongs in the service, and everything else belongs in the store. Authentication, protocol translation, validation, encryption, and delivering changes to watchers all require payload or caller context, so they stayed in the application. Persistence, replication, failover, ordered change streams, expiry, and pub/sub depend on neither, and Valkey already provides them.

Replacing the backend added about 2,400 lines and removed nearly 18,000. The API servers became stateless, existing clients kept their REST and WebSocket access, and the old cluster join and remove endpoints now return 410 Gone since there is no longer an application cluster to join. Valkey still has to be operated, and the hard distributed-systems work now belongs to that project rather than to our configuration service.

Keeping multi-key writes atomic

Removing Raft exposed a property the replicated log had been providing automatically. When every committed entry applies in a single order to one local state machine, everything derived from a mutation stays consistent without extra coordination.

On Valkey, a single configuration write touches a hash for the entry and its version, a set for key indexing, a sorted set for expiry tracking, a sequence counter, an ordered change stream, and a pub/sub channel for live watchers. Issuing those commands separately from a stateless API server would let concurrent requests interleave across keys, or leave the value and its derived state out of sync if the caller failed mid-write.

To preserve single-step consistency without adding locking to the API servers, every mutation became a Lua script. Valkey executes a script atomically, blocking other server activity until it finishes, so all of its effects become visible together and no client can observe a half-applied write.

Handling concurrent writers

Multiple clients updating the same configuration key still need protection against stale writes, and validating a version in the API server before issuing a separate write would leave a check-then-act race. Because each mutation already runs inside a Lua script, the client sends the version it read and the script checks that expected version against the stored one before modifying anything. If another write landed first, the script exits early and the API returns 409.

The concurrency test fires 32 concurrent writers with the same expected version and asserts exactly one 200 and 31 409s. That test runs against an in-memory model of the script, so it verifies how the API behaves under contention while atomicity in production rests on Valkey’s script execution guarantee.

Durability after Raft

Handing storage to Valkey also shifts the durability contract. An embedded Raft cluster determines what survives a node failure through quorum commitment across the service’s own voters; behind stateless API servers, that promise comes directly from Valkey’s replication and failover. Tightening or relaxing the guarantee is now an operational choice on the Valkey deployment rather than code in the service.

Chris Chabot, November 2026