A pluggable backend API that enforces the Event Sourcing Pattern for persisting & broadcasting application state changes

Overview

stategate

A pluggable "Application State Gateway" that enforces the Event Sourcing Pattern for securely persisting & broadcasting application state changes

What is Event Sourcing?

Event sourcing persists the state of a business entity such an Order or a Customer as a sequence of state-changing events. Whenever the state of a business entity changes, a new event is appended to the list of events. Since saving an event is a single operation, it is inherently atomic. The application reconstructs an entity’s current state by replaying the events.

Applications persist events in an event store, which is a database of events. The store has an API for adding and retrieving an entity’s events. The event store also behaves like a message broker. It provides an API that enables services to subscribe to events. When a service saves an event in the event store, it is delivered to all interested subscribers.

Event-Sourcing

GoDoc

Features

  • 6 simple API Methods for interacting with application state:

    • SetObject sets the current state value of an object, adds it to the event log, then broadcast the event to all interested consumers
    • GetObject gets an object's current state values
    • DelObject hard deletes an object & all of it's events
    • SearchObjects queries objects of a specific type
    • StreamEvents creates an event stream/subscription to a given object type until fn returns false OR the context cancels.
    • SearchEvents queries events related to a specific object.
  • Multi-Tenant

  • Capture all changes to an application's state as a sequence of events.

  • Stateless & horizontally scaleable

  • Native gRPC support

  • Embedded REST support / (transcoding)

  • Embedded grpcweb support (transcoding)

  • Metrics Server(prometheus/pprof)

  • Authentication - JWT/OAuth with remote JWKS verification

  • Authorization - Rego based Authorization engine

  • Autogenerated Client gRPC SDK's

  • Structured JSON Logs

  • Sample Kubernetes Manifest

  • Sample Docker Compose

  • Pluggable "Channel" Providers

    • In-Memory(won't scale horizontally)
      • fully-tested
    • Nats
      • fully-tested
    • Nats Streaming(Stan)
    • Redis
      • fully-tested
    • Kafka
    • RabbitMQ
  • Pluggable "Storage" Providers

    • MongoDb
      • fully-tested
    • PostgreSQL
    • MySQL
    • Cassandra

Goals

  • Create a simple API interface for storing state and subscribing to state changes(events) using pluggable channel & storage providers
  • Capture all changes to an application's state as a sequence of events.
  • Safe to swap backend providers without changing client-side code
  • Type-safe client's generated in many languages
  • Safe to expose to the public internet due to fine-grained authentication/authorization model.
  • Different combinations of Channel & Storage Providers are interoperable.
  • Capture a persistant, immutable historical record of all state changes using a pluggable storage provider
  • Store identity(jwt.claims) & timestamp in event logs to capture who is changing what & when
  • Easy deployment model - fully configureable via environmental variables

Concepts

  • Storage Provider: A stategate storage provider is a pluggable, 3rd party database storage service. Storage providers provide persistance for all objects & events and should be scaled independently of stategate instances.

  • Channel Provider: A stategate channel provider is a pluggable, 3rd party message-queue/channel service. Channel providers provide a way for stategate to broadcast events to itself while scaling horizontally. Channel providers should be scaled independently of stategate instances.

Environmental Variables

# port to serve on (optional). defaults to 8080
STATEGATE_PORT=8080
# enable debug logs (optional)
STATEGATE_DEBUG=true
# disable all authentication & authorization(jwks, request policies, response policies) (optional)
STATEGATE_AUTH_DISABLED=false
# tls cert file (optional)
STATEGATE_TLS_CERT_FILE=/tmp/certs/stategate.cert
# tls key file (optional)
STATEGATE_TLS_KEY_FILE=/tmp/certs/stategate.key

# JSON Web Key Set remote URI used for fetching jwt signing keys for verification/validation (optional)
STATEGATE_JWKS_URI=https://www.googleapis.com/oauth2/v3/certs

# base64 encoded OPA rego policy executed on inbound requests from clients (optional)
STATEGATE_REQUEST_POLICY=cGFja2FnZSBzdGF0ZWdhdGUuYXV0aHoKCmRlZmF1bHQgYWxsb3cgPSB0cnVl
# base64 encoded OPA rego policy executed on responses sent to clients (optional)
STATEGATE_RESPONSE_POLICY=cGFja2FnZSBzdGF0ZWdhdGUuYXV0aHoKCmRlZmF1bHQgYWxsb3cgPSB0cnVl
# channel provider configuration(JSON) options: [inmem, redis, nats, stan, kafka] REQUIRED
STATEGATE_CHANNEL_PROVIDER={ "name": "redis", "addr": "localhost:6379" }
# STATEGATE_CHANNEL_PROVIDER={ "name": "nats", "addr": "localhost:4222" }
# STATEGATE_CHANNEL_PROVIDER={ "name": "stan", "addr": "localhost:4222" }
# STATEGATE_CHANNEL_PROVIDER={ "name": "inmem" }

# storage provider configuration(JSON) options: [mongo] REQUIRED
STATEGATE_STORAGE_PROVIDER={ "name": "mongo", "database": "testing", "addr": "mongodb://localhost:27017/testing" }

Notes

You might also like...
This is a simple HTTP application that returns system info

sysinfo This is a simple HTTP application that returns system info. Trace Support There is also simple OpenTelemetry tracing support via the -t flag.

Go API backed by the native Dart Sass Embedded executable.

This is a Go API backed by the native Dart Sass Embedded executable. The primary motivation for this project is to provide SCSS support to Hugo. I wel

The easiest way to make API documents for GraphQL

Document Generator for GraphQL gqldoc is now alpha gqldoc is command line tool to generate documents from GraphQL schema or your GraphQL endpoint. the

reflect api without runtime reflect.Value cost

reflect2 reflect api that avoids runtime reflect.Value cost reflect get/set interface{}, with type checking reflect get/set unsafe.Pointer, without ty

Cross-platform Bluetooth API for Go and TinyGo.
Cross-platform Bluetooth API for Go and TinyGo.

Go Bluetooth is a cross-platform package for using Bluetooth Low Energy hardware from the Go programming language.

this is an api that execute your deno code and send you the output

this a simple api that execute your deno code and send you the output, has not limit per request example request: in deno: const rawResponse = await f

Go scripts for finding an API key / some keywords in repository
Go scripts for finding an API key / some keywords in repository

Git-Secret Go scripts for finding an API key / some keywords in repository Update V1.0 🚀 Added some API Key checker Screenshoot 📷 How to Install go

🚀 Use Lanyard API easily in your Go app!

🚀 Go Lanyard Use Lanyard API easily in your Go app! 📦 Installation Initialize your project (go mod init example.com/example) Add package (go get git

A simple API for computing diffs of your documents over the time built on a scalable technology stack.

Diffme API WIP - this is an API to compute diffs between documents. It serves as a way to easily create audit logs for documents in your system, think

Owner
Coleman Word
Full stack(Go/Typescript) + Devops engineer
Coleman Word
gobreaker implements the Circuit Breaker pattern in Go.

gobreaker gobreaker implements the Circuit Breaker pattern in Go.

Sony 2.3k Jan 7, 2023
A convenient library to do a must pattern

must A convenient library to do a must pattern Problems Before Go 1.18, if you want to panic when the regular expression cannot compile, you need to d

Thanabodee Charoenpiriyakij 3 Nov 15, 2022
Singlestore event analytics - Evaluation of sortable ID generation schemes

Singlestore event analytics - Evaluation of sortable ID generation schemes

Carl Sverre 1 Jan 25, 2022
Observer - Golang event dispatch

observer go基于观察者模式的事件调度 Installation go get -u github.com/caijw-go/observer Usa

null 1 Jan 22, 2022
Instagram Backend API Using GO

InstaCloneGo ⚡ Instagram Backend API Using GO Setup ❄️ go run server.go API END POINTS CREATE USERS :http://localhost:8001/users GET A USER USING ID

NAVEEN 1 Oct 10, 2021
Tugas Alta Immersive Backend Golang Fundamental Programming (Pointer, Struct, Method, Interface)

Tatacara Melakukan Setup Tugas clone project ini dengan cara git clone https://github.com/Immersive-Backend-Resource/Pointer-Struct-Method-Interface.g

null 0 Jan 9, 2022
Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Billy 19 Mar 8, 2022
A set of instrumentation features for collecting relevant tracing data as well as secure an application

Go Agent goagent provides a set of instrumentation features for collecting relevant tracing data as well as secure an application by blocking requests

null 0 Dec 21, 2021
Drone eReg: Demo client application for the PKI server's built-in UAV registry

UAV e-Registration: Demo UAV Registry Client A client to register UAVs in the built-in demo UAV registry of the UAVreg-PKI-server. Installation and Us

consider it GmbH 0 Jan 5, 2022
An application written in Go to generate fractals like the Mandelbrot set and the Julia set.

Fractals An application written in Go to generate fractals like the Mandelbrot set and the Julia set. Screenshots Mandelbrot set Julia set Prerequisit

null 0 May 9, 2022