All Projects → shijuvar → Go Distributed Sys

shijuvar / Go Distributed Sys

Licence: apache-2.0
A simple example on Event Sourcing/CQRS in Go for building distributed systems and microservices with NATS Streaming, gRPC and CockroachDB

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Go Distributed Sys

Go Micro Boilerplate
The boilerplate of the GoLang application with a clear microservices architecture.
Stars: ✭ 147 (-58%)
Mutual labels:  grpc, nats
Gokit
Go Examples: From basics to distributed systems
Stars: ✭ 325 (-7.14%)
Mutual labels:  grpc, nats
Liftbridge
Lightweight, fault-tolerant message streams.
Stars: ✭ 2,175 (+521.43%)
Mutual labels:  grpc, nats
Golang Examples
Stars: ✭ 114 (-67.43%)
Mutual labels:  grpc, nats
liftbridge-api
Protobuf definitions for the Liftbridge gRPC API. https://github.com/liftbridge-io/liftbridge
Stars: ✭ 15 (-95.71%)
Mutual labels:  grpc, nats
Gb28181.solution
Linux/Win/Docker/kubernetes/Chart/Kustomize/GB28181/SIP/RTP/SDP/WebRTC/作为上下级域/平台级联互联
Stars: ✭ 323 (-7.71%)
Mutual labels:  grpc
Furan
Scale out Docker builds
Stars: ✭ 339 (-3.14%)
Mutual labels:  grpc
Nats.go
Golang client for NATS, the cloud native messaging system.
Stars: ✭ 3,690 (+954.29%)
Mutual labels:  nats
Go Grpc Tutorial
A simple tutorial about Golang gRPC.
Stars: ✭ 315 (-10%)
Mutual labels:  grpc
Launcher
Osquery launcher, autoupdater, and packager
Stars: ✭ 346 (-1.14%)
Mutual labels:  grpc
Go Project Sample
Introduce the best practice experience of Go project with a complete project example.通过一个完整的项目示例介绍Go语言项目的最佳实践经验.
Stars: ✭ 344 (-1.71%)
Mutual labels:  grpc
Grpc Web
gRPC Web implementation for Golang and TypeScript
Stars: ✭ 3,722 (+963.43%)
Mutual labels:  grpc
Natsboard
Dashboard for monitoring NATS (an open source messaging system)
Stars: ✭ 339 (-3.14%)
Mutual labels:  nats
Rejoiner
Generates a unified GraphQL schema from gRPC microservices and other Protobuf sources
Stars: ✭ 3,432 (+880.57%)
Mutual labels:  grpc
Ts Proto
An idiomatic protobuf generator for TypeScript
Stars: ✭ 340 (-2.86%)
Mutual labels:  grpc
Vertx Zero
Zero Framework:http://www.vertxup.cn
Stars: ✭ 320 (-8.57%)
Mutual labels:  grpc
Grpcox
Like Postman, but for gRPC: web based GUI client for gRPC Development Testing
Stars: ✭ 333 (-4.86%)
Mutual labels:  grpc
Go Grpc Middleware
Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Stars: ✭ 4,170 (+1091.43%)
Mutual labels:  grpc
Grpc Http Proxy
A reverse proxy server which translate JSON HTTP requests to gRPC calls based on protoreflect
Stars: ✭ 328 (-6.29%)
Mutual labels:  grpc
Tonic
A native gRPC client & server implementation with async/await support.
Stars: ✭ 4,422 (+1163.43%)
Mutual labels:  grpc

The updated source code is moved into the repository go-distsys

go-distributed-sys

Check out the article Building Microservices with Event Sourcing/CQRS in Go using gRPC, NATS Streaming and CockroachDB

Technologies Used:

  • Go
  • NATS Streaming
  • gRPC
  • CockroachDB

Compile Proto files

Run the command below from the nats-streaming directory:

protoc -I pb/ pb/*.proto --go_out=plugins=grpc:pb

Set up CockroachDB

Create user

cockroach user set shijuvar --insecure

Create Database

cockroach sql --insecure -e 'CREATE DATABASE ordersdb'

Grant privileges to the shijuvar user

cockroach sql --insecure -e 'GRANT ALL ON DATABASE ordersdb TO shijuvar'

Start CockroachDB Cluster

Start node 1:

cockroach start --insecure
--store=ordersdb-1
--host=localhost
--background

Start node 2:

cockroach start --insecure
--store=ordersdb-2
--host=localhost
--port=26258
--http-port=8081
--join=localhost:26257
--background

Start node 3:

cockroach start --insecure
--store=ordersdb-3
--host=localhost
--port=26259
--http-port=8082
--join=localhost:26257
--background

Start a SQL Shell for CockroachDB:

cockroach sql
--url="postgresql://[email protected]:26257/ordersdb?sslmode=disable";

Run NATS Streaming Server

nats-streaming-server
--store file
--dir ./data
--max_msgs 0
--max_bytes 0

Basic Workflow in the example:

  1. A client app post an Order to an HTTP API.
  2. An HTTP API (orderservice) receives the order, then executes a command onto Event Store, which is an immutable log of events, to create an event via its gRPC API (eventstore).
  3. The Event Store API executes the command and then publishes an event "order-created" to NATS Streaming server to let other services know that an event is created.
  4. The Payment service (paymentservice) subscribes the event “order-created”, then make the payment, and then create an another event “order-payment-debited” via Event Store API.
  5. The Query syncing workers (orderquery-store1 and orderquery-store2 as queue subscribers) are also subscribing the event “order-created” that synchronise the data models to provide state of the aggregates for query views.
  6. The Event Store API executes a command onto Event Store to create an event “order-payment-debited” and publishes an event to NATS Streaming server to let other services know that the payment has been debited.
  7. The restaurant service (restaurantservice) finally approves the order.
  8. A Saga coordinator manages the distributed transactions and makes void transactions on failures (to be implemented).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].