Purchase service of my saga pattern implementation.
Features:
- Realtime event-driven subscription using Redis Stream and server-sent events (SSE)
- Prometheus metrics
- Distributed tracing with OpenTelemetry
- HTTP server
- gPRC client
- Comprehensive application struture with domain-driven design (DDD), decoupling service implementations from configurations and transports
- Compile-time dependecy injection using wire
- Graceful shutdown
- Unit testing and continuous integration using Drone CI
Setup githooks:
git config core.hooksPath githooks
Build from source:
go mod tidy
make build
Start the service:
REDIS_ADDRS=redis-node1:7000,redis-node2:7001 \
REDIS_PASSWORD=pass.123 \
NATS_URL=nats://nats-streaming:4222 \
NATS_CLUSTER_ID=test-cluster \
RPC_AUTH_SVC_HOST=saga-account:8000 \
RPC_PRODUCT_SVC_HOST=saga-product:8000 \
JAEGER_URL=http://jaeger:14268/api/traces \
./server
Test locally:
make test
REDIS_ADDRS
: list of Redis addressesREDIS_PASSWORD
: Redis passwordNATS_URL
: NATS Streaming server URL.NATS_CLUSTER_ID
: NATS Cluster IDRPC_AUTH_SVC_HOST
: gRPC account service hostRPC_PRODUCT_SVC_HOST
: gRPC product service hostJAEGER_URL
: Jaeger collector URL
See docker-compose example for details.
Metric | Description | Labels |
---|---|---|
purchase_pubsub_subscriber_messages_received_total | A Prometheus Counter. Counts the number of messages obtained by the subscriber. | acked ("acked" or "nacked"), handler_name , subscriber_name |
purchase_pubsub_publish_time_seconds (purchase_pubsub_publish_time_seconds_count, purchase_pubsub_publish_time_seconds_bucket, purchase_pubsub_publish_time_seconds_sum) | A Prometheus Histogram. Registers the time of execution of the Publish function of the decorated publisher. | handler_name , success ("true" or "false"), publisher_name |
purchase_http_request_duration_seconds (purchase_http_request_duration_seconds_count, purchase_http_request_duration_seconds_bucket, purchase_http_request_duration_sum) | A Prometheus histogram. Records the latency of the HTTP requests. | code , handler , method |
purchase_http_requests_inflight | A Prometheus gauge. Records the number of inflight requests being handled at the same time. | code , handler , method |
purchase_http_response_size_bytes (purchase_http_response_size_bytes_count, purchase_http_response_size_bytes_bucket, purchase_http_response_size_bytes_sum) | A Prometheus histogram. Records the size of the HTTP responses. | handler |