Control plane
BigConfig Store is a library for implementing the desired state of a control plane with an audit log. It uses Redis Sorted Sets to store the events and the snapshots.
- Get enough RAM to hold all your data.
- Implement the business logic of the control plane as a PURE event-handling function.
- Keep the control loop separate from the event-handling function.
- All events need to be replayable and produce the same state.
- Start Redis in a shell
Terminal window redis-server - Require the store library
(ns my-control-plane(:require[big-config.store :refer [store! handle!]]))
- The pure business logic
; Your business logic as a pure function. Returns the new state with event applied.(defn my-business [state event timestamp](case event:reset {:counter 0}:inc (update state :counter inc)))
- Increment the counter two times
(with-open [p1 (store! {:business-fn my-business:wcar-opts {:pool :none}})]; The default initial state is an empty map.; :reset will set the state to {:counter 0}(handle! p1 :reset)(assert (= @p1 {:counter 0})); Your events can be any Clojure value or Serializable object.(handle! p1 :inc)(handle! p1 :inc); Your system state with the events applied.(assert (= @p1 {:counter 2}))@p1)
- Read the counter again
(with-open [p2 (store! {:business-fn my-business:wcar-opts {:pool :none}})]; the state is recovered, even if there was a system crash.(assert (= @p2 {:counter 2}))@p2)
Shortcomings
Section titled “Shortcomings”- RAM: It requires enough RAM to hold all the data in your business state.
- Start-up time: The entire state is read into RAM.
Credit
Section titled “Credit”BigConfig Store is a reimplementation of prevayler-clj in Redis.
Use case Control plane
Blog article Demystifying the control plane: the easy upgrade path from GitOps with BigConfig