Skip to content

DenysFizer/Not_Contest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sales Service

A microservice for handling sales operations with checkout and purchase functionality, built with Go.

Project Structure

.
├── 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

Running the Service

# 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

Features

  • 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

Configuration

Configure the service using environment variables or .env file:

  • Database connection
  • Redis settings
  • Server port
  • Other service parameters

Main Logic Feature

  • Sale start every hour
  • Error responses from load tester save to file
  • Create indexes

Load Test

  • just Ctrl + c when u want to check stats
  • error logs from load tester is saved in file
  • reading from redis items IDs

Performance Test Results

Scenario 1: Heavy Load with Higher Purchase Rate

Test Configuration

  • 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)

Performance Metrics

Metric Value
Average Latency 33.9ms
Minimum Latency 466µs
Maximum Latency 417.8ms

Latency Distribution

Percentile Latency
P50 (Median) 33.9ms
P90 67.8ms
P99 101.7ms

Analysis

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.

Scenario 2: Mixed Load Pattern

Test Configuration

  • Duration: 9 minutes 17 seconds
  • Total Requests: 105,298
  • Success Rate: 43.9% (46,202 successful requests)

Request Distribution

Operation Type Successful Requests
Checkouts 14,449
Purchases 8,652
Failed Requests 59,096

Performance Metrics

Metric Value
Average Latency 21.2ms
Minimum Latency 427µs
Maximum Latency 660ms

Latency Distribution

Percentile Latency
P50 (Median) 21.2ms
P90 42.3ms
P99 63.5ms

Analysis

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

Comparative Analysis

  1. Latency Performance:

    • Scenario 2 shows better latency metrics across all percentiles
    • Both scenarios maintain sub-100ms latency for 99% of requests
  2. Success Rates:

    • Scenario 1: 66.9% success rate
    • Scenario 2: 43.9% success rate
  3. Request Patterns:

    • Scenario 1: Higher purchase rate
    • Scenario 2: More balanced checkout/purchase distribution
  4. System Behavior:

    • Both scenarios show consistent latency patterns
    • Higher failure rates indicate potential areas for optimization in concurrent request handling

Environment Configuration

Database Configuration

  • DB_HOST: Database server hostname or IP address
  • DB_PORT: PostgreSQL server port number
  • DB_USER: Database user credentials
  • DB_PASSWORD: Database user password
  • DB_NAME: Name of the database to connect to
  • DB_SSL_MODE: SSL connection mode for database security

Redis Configuration

  • REDIS_HOST: Redis server hostname or IP address
  • REDIS_PORT: Redis server port number
  • REDIS_PASSWORD: Redis authentication password
  • REDIS_TTL: Time-to-live for cached items in Hours

Application Configuration

  • APP_PORT: HTTP server port for the main application
  • APP_ITEM_NUMBER: Sale limit
  • APP_USER_LIMIT: User limit
  • APP_METRICS_PORT: Port for Prometheus metrics endpoint

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published