Logistics Microservice Runbook - Wiz-DevTech/prettygirllz GitHub Wiki

Logistics Microservice Runbook

System Overview

The Logistics Microservice is a Spring Boot application that manages delivery operations and fraud detection. It provides REST APIs for creating and managing deliveries, with integrated fraud detection capabilities.

Key Components

  • Database: PostgreSQL with Flyway migrations
  • Messaging: Apache Kafka
  • Caching: Redis
  • Framework: Spring Boot 2.x/3.x
  • Build Tool: Maven/Gradle (inferred)

Prerequisites

Software Requirements

  • Java 17 or higher
  • PostgreSQL 12+
  • Apache Kafka 2.8+
  • Redis 6.0+
  • Maven 3.6+ or Gradle 7+

System Requirements

  • RAM: 2GB minimum, 4GB recommended
  • Disk Space: 1GB minimum
  • Network: Access to PostgreSQL, Kafka, and Redis

Installation & Setup

1. Database Setup

-- Connect to PostgreSQL and create database
CREATE DATABASE logisticsdb;
CREATE USER logistics WITH PASSWORD 'secret';
GRANT ALL PRIVILEGES ON DATABASE logisticsdb TO logistics;

2. Configure Database Schema

The application uses Flyway for database migrations. The following tables will be created:

  • logistics.deliveries - Stores delivery information
  • logistics.fraud_blacklist - Stores fraud detection data

3. Environment Configuration

Create/update environment-specific configuration files:

application.yml

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/logisticsdb
    username: logistics
    password: secret
  kafka:
    bootstrap-servers: localhost:9092
  data:
    redis:
      host: localhost
      port: 6379
server:
  port: 8080

Starting the Service

Development Mode

# Using Maven
mvn spring-boot:run

# Using Gradle
./gradlew bootRun

# Using JAR
java -jar target/logistics-service-*.jar

Production Mode

# Set production profile
export SPRING_PROFILES_ACTIVE=prod

# Start with production configuration
java -Dspring.profiles.active=prod -jar logistics-service.jar

Service Health Checks

Health Endpoints

  • Application Health: GET /api/actuator/health
  • Database Connectivity: Check via health endpoint
  • Redis Status: Monitor via configuration

Manual Health Verification

# Check if service is running
curl http://localhost:8080/api/actuator/health

# Test API endpoints
curl http://localhost:8080/api/v1/deliveries?status=CREATED

Monitoring & Logging

Key Metrics to Monitor

  • JVM Metrics: Heap usage, GC activity
  • Database Connections: HikariCP pool metrics
  • API Response Times: Track endpoint performance
  • Error Rates: Monitor 4xx/5xx responses

Log Locations

  • Application Logs: Console output or specified log file
  • Database Logs: PostgreSQL logs for slow queries
  • Kafka Logs: Consumer/Producer events

Important Log Messages

  • Startup sequence completion
  • Database migration status
  • Kafka connection status
  • Fraud detection alerts

Common Troubleshooting

Database Issues

Problem: Connection refused to PostgreSQL

# Check PostgreSQL status
sudo systemctl status postgresql

# Verify connection parameters
psql -h localhost -U logistics -d logisticsdb

Problem: Schema not found

  • Verify Flyway migrations have run successfully
  • Check flyway_schema_history table

Kafka Issues

Problem: Cannot connect to Kafka broker

# Check Kafka status
sudo systemctl status kafka

# Verify broker is accessible
kafka-topics.sh --list --bootstrap-server localhost:9092

Redis Issues

Problem: Redis connection timeout

# Check Redis status
redis-cli ping

# Monitor Redis logs
tail -f /var/log/redis/redis-server.log

API Issues

Problem: 404 errors for API endpoints

  • Verify server.servlet.context-path is set to /api
  • Check if application started successfully
  • Validate URI patterns match controller mappings

Problem: Delivery creation fails

  • Check fraud detection service is operational
  • Verify recipient data validation
  • Monitor database constraints

Maintenance Procedures

Database Maintenance

-- Analyze database performance
ANALYZE;

-- Update table statistics
VACUUM ANALYZE logistics.deliveries;
VACUUM ANALYZE logistics.fraud_blacklist;

Log Rotation

  • Configure logback-spring.xml for log rotation
  • Monitor disk space usage
  • Archive or delete old logs as needed

Backup Procedures

# Database backup
pg_dump -h localhost -U logistics logisticsdb > backup_$(date +%Y%m%d).sql

# Create database snapshot
pg_dump -h localhost -U logistics -F c logisticsdb > backup_$(date +%Y%m%d).backup

Security Considerations

Database Security

  • Use connection pooling (HikariCP configured)
  • Implement proper authentication
  • Regularly update passwords

API Security

  • Consider implementing authentication/authorization
  • Add rate limiting if needed
  • Validate input data thoroughly

Performance Tuning

Database Optimization

  • Monitor slow queries
  • Add indexes as needed
  • Tune HikariCP settings

Application Optimization

  • Monitor memory usage
  • Tune JVM parameters
  • Optimize query patterns

Deployment Strategies

Blue-Green Deployment

  1. Deploy new version to staging environment
  2. Run integration tests
  3. Switch traffic to new instance
  4. Monitor performance and rollback if needed

Rolling Deployment

  1. Update one instance at a time
  2. Verify health before proceeding
  3. Continue with remaining instances

Emergency Procedures

Service Restart

# Graceful shutdown
kill -TERM <PID>

# Force restart if needed
kill -KILL <PID>

# Restart service
java -jar logistics-service.jar

Database Recovery

  1. Stop application
  2. Restore from backup
  3. Run any necessary migrations
  4. Restart application

Rollback Procedures

  1. Stop current version
  2. Deploy previous stable version
  3. Verify functionality
  4. Monitor for any issues

Contact Information

  • Development Team: [team-email]
  • Database Administrator: [dba-email]
  • On-Call Support: [oncall-contact]
  • Documentation: [wiki-url]
⚠️ **GitHub.com Fallback** ⚠️