A microservice for handling sales operations with checkout and purchase functionality, built with Go.
.
├── cmd/ # Application entrypoints
├── config/ # Configuration management
├── load_tester/ # Load testing utilities
├── pkg/ # Core packages
│ ├── cache/ # Redis caching
│ ├── repository/ # Database operations
│ ├── server/ # HTTP server
│ └── services/ # Business logic
└── utils/ # Shared utilities
# Build and start all services
docker compose up --build# Stop and remove all containers, networks, and volumes
docker compose down -v# To run load test
go run load_tester/main.go- RESTful API for sales operations
- Checkout and purchase processing
- Redis caching for performance
- PostgreSQL database for persistence
- Prometheus metrics integration
- Graceful shutdown handling
- Docker support
Configure the service using environment variables or .env file:
- Database connection
- Redis settings
- Server port
- Other service parameters
- Sale start every hour
- Error responses from load tester save to file
- Create indexes
- just Ctrl + c when u want to check stats
- error logs from load tester is saved in file
- reading from redis items IDs
- Duration: 13 minutes 20 seconds
- Request Pattern: Heavy load with higher purchase rate (see load.go line 217)
- Total Requests: 94,492
- Success Rate: 66.9% (63,168 successful requests)
| Metric | Value |
|---|---|
| Average Latency | 33.9ms |
| Minimum Latency | 466µs |
| Maximum Latency | 417.8ms |
| Percentile | Latency |
|---|---|
| P50 (Median) | 33.9ms |
| P90 | 67.8ms |
| P99 | 101.7ms |
The service demonstrates consistent performance under high load with:
- Sub-100ms latency for 99% of requests
- Median latency of 33.9ms
- Maximum observed latency of 417.8ms
The 33.1% failure rate (31,324 failed requests) indicates potential areas for optimization in handling concurrent requests and resource management.
- Duration: 9 minutes 17 seconds
- Total Requests: 105,298
- Success Rate: 43.9% (46,202 successful requests)
| Operation Type | Successful Requests |
|---|---|
| Checkouts | 14,449 |
| Purchases | 8,652 |
| Failed Requests | 59,096 |
| Metric | Value |
|---|---|
| Average Latency | 21.2ms |
| Minimum Latency | 427µs |
| Maximum Latency | 660ms |
| Percentile | Latency |
|---|---|
| P50 (Median) | 21.2ms |
| P90 | 42.3ms |
| P99 | 63.5ms |
The second scenario shows:
- Improved latency metrics compared to Scenario 1
- Lower success rate (43.9%) indicating higher system stress
- Consistent sub-100ms latency for 99% of requests
- Higher failure rate (56.1%) suggesting potential bottlenecks under mixed load patterns
- Fails request not shows error on server it shown error on request side check err logs
-
Latency Performance:
- Scenario 2 shows better latency metrics across all percentiles
- Both scenarios maintain sub-100ms latency for 99% of requests
-
Success Rates:
- Scenario 1: 66.9% success rate
- Scenario 2: 43.9% success rate
-
Request Patterns:
- Scenario 1: Higher purchase rate
- Scenario 2: More balanced checkout/purchase distribution
-
System Behavior:
- Both scenarios show consistent latency patterns
- Higher failure rates indicate potential areas for optimization in concurrent request handling
DB_HOST: Database server hostname or IP addressDB_PORT: PostgreSQL server port numberDB_USER: Database user credentialsDB_PASSWORD: Database user passwordDB_NAME: Name of the database to connect toDB_SSL_MODE: SSL connection mode for database security
REDIS_HOST: Redis server hostname or IP addressREDIS_PORT: Redis server port numberREDIS_PASSWORD: Redis authentication passwordREDIS_TTL: Time-to-live for cached items in Hours
APP_PORT: HTTP server port for the main applicationAPP_ITEM_NUMBER: Sale limitAPP_USER_LIMIT: User limitAPP_METRICS_PORT: Port for Prometheus metrics endpoint