Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/morzhanov/go-event-sourcing
Go CQRS + Event Sourcing example application
https://github.com/morzhanov/go-event-sourcing
Last synced: 5 days ago
JSON representation
Go CQRS + Event Sourcing example application
- Host: GitHub
- URL: https://github.com/morzhanov/go-event-sourcing
- Owner: morzhanov
- Created: 2021-10-10T12:56:39.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-12T18:15:47.000Z (about 3 years ago)
- Last Synced: 2024-11-08T00:52:36.480Z (about 2 months ago)
- Language: Go
- Size: 60.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Event Sourcing Example
Go CQRS + Event Sourcing example application.
## CQRS and Event Sourcing
CQRS stands for Command and Query Responsibility Segregation, a pattern that separates read and update operations for a data store. Implementing CQRS in your application can maximize its performance, scalability, and security. The flexibility created by migrating to CQRS allows a system to better evolve over time and prevents update commands from causing merge conflicts at the domain level.
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.
Nice article on Event Sourcing.
## Project Architecture
- Orders - service for order creation and retrieval
- Commands used for order creation and processing
- Queries used for orders retrieval
- Processor - dumb service which mocks order processing
- Command store - persists commands (MongoDB)
- Query store - consumes events from kafka commands channel and saves/updates data for queries (PostgreSQL)
- Kafka - used as communication level between Command-Query stores and Order-Processor services## Running
1. `cd /deploy`
2. `docker-compose up -d`
3. `cd ../`
4. `go run cmd/processor/main.go`
5. `go run cmd/orders/main.go`After that you'l be able to run commands and queries.
## Commands
### Create Order
```bash
curl --location --request POST '127.0.0.1:8080' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "someid",
"name": "somename",
"status": "new"
}'
```### Process Order
```bash
curl --location --request POST '127.0.0.1:8080/someid' --data-raw ''
```## Queries
### Get Orders
```bash
curl --location --request GET '127.0.0.1:8080'
```### Get Order
```bash
curl --location --request GET '127.0.0.1:8080/someid'
```