Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

chief-of-state/chief-of-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

933 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chief of State

GitHub Workflow Status (branch) codecov GitHub release (latest SemVer including pre-releases) GitHub

Table of Contents

🎯 Overview

Chief of State (CoS) is an open-source clustered persistence tool for building event-sourced applications. CoS supports CQRS and event-sourcing through simple, language-agnostic interfaces via gRPC or HTTP/JSON, and it lets you describe your schema with Protobuf. Under the hood, CoS leverages Apache Pekko to scale out and deliver performant, reliable persistence.

Chief of State was built with these principles:

  • Wire format should be the same as persistence
  • Scaling should not require re-architecture
  • Developers shouldn't face race conditions or database locks
  • Rules should be enforced with interfaces
  • Event sourcing is valuable but challenging to implement
  • An ideal event-sourcing datastore would offer random access by key, streaming, and atomic writes

Chief of State was created in 2020 at Namely based on the principles above.

πŸ“Œ Note

If your company is still using the Namely version and wants to migrate to this fork, you must be at least on namely v0.9.2-rc.1. See the documentation for setup instructions.

From version v2.4.11 onward, Chief of State has been fully migrated from Akka to Apache Pekko. Projects on versions before that cannot be upgraded to the latest releases due to the lack of a migration kit at this time.

✨ Features

  • Journal & Snapshot β€” Serialization using Google Protocol Buffer message format
  • Clustering β€” Preconfigured clustering and domain entity sharding with the split-brain-resolver algorithm
  • Caching β€” Automatic caching and entity Passivation
  • Storage β€” Automatic configuration of PostgreSQL storage on boot
  • Observability β€” OpenTelemetry integration for tracing and metrics
  • Compaction β€” Journal compaction support
  • Kubernetes β€” Direct integration to form a cluster using the Kubernetes API
  • Subscriptions β€” Real-time events streaming without interacting with the Journal Store
  • Read Side Management β€” Via the CLI tool:
    • Skip offset per shard and across the whole CoS cluster
    • Pause, resume, and restart read sides per shard or cluster-wide
    • List read sides' offsets per shard and across the cluster

🏭 Production

Chief of State has been used in production by notable companies since 2020.

πŸ—οΈ Anatomy of a Chief of State App

You implement two handler interfaces (gRPC or HTTP): a write handler to process commands and events, and optionally many read handlers that react to state changes by consuming events from the write handler.

Architecture Diagram

Chief of State Service

The main entry point is the Service. You interact with Chief of State via:

  • ProcessCommand β€” Send commands to be processed by the Write Handler
  • GetState β€” Retrieve the current state of a persistent entity

Write Handler

You describe state mutations by implementing two RPCs in the WriteSideHandlerService:

  • HandleCommand β€” Accepts a command and the prior state, returns an event. For example, given UpdateUserEmail and a User, it might return UserEmailUpdated.
  • HandleEvent β€” Accepts an event and the prior state, returns the new state. For example, given UserEmailUpdated and a User, it returns a new User instance with the email updated.

Read Handler

In response to state mutations, CoS sends changes to many ReadSideHandlerService implementations. CoS guarantees at-least-once delivery of events and resulting state to each read side, in the order they were persisted.

Read side handlers can:

  • Write state changes to a data store (e.g., Elasticsearch)
  • Publish changes to Kafka topics
  • Send notifications to users in response to specific events

πŸ“š Documentation

πŸ’¬ Community

Join the discussion and ask Chief of State–related questions:

GitHub Discussions

🀝 Contribution

Contributions are welcome!

The project adheres to Semantic Versioning and Conventional Commits. If you see an issue you'd like to fix, the best way is to submit a pull request. To test your changes locally:

# Install Earthly CLI (macOS)
brew install earthly/earthly/earthly

# Build the Docker image
earthly +build-image

# Run tests
earthly -P --no-output +test-local

Tip: See the Earthly docs for installation on Linux and Windows.

πŸ“„ License

License: MIT

Chief of State is free and will remain so, with no paid license requirement.

πŸš€ Sample Projects