Logistics Microservice Runbook - Wiz-DevTech/prettygirllz GitHub Wiki
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.
- Database: PostgreSQL with Flyway migrations
- Messaging: Apache Kafka
- Caching: Redis
- Framework: Spring Boot 2.x/3.x
- Build Tool: Maven/Gradle (inferred)
- Java 17 or higher
- PostgreSQL 12+
- Apache Kafka 2.8+
- Redis 6.0+
- Maven 3.6+ or Gradle 7+
- RAM: 2GB minimum, 4GB recommended
- Disk Space: 1GB minimum
- Network: Access to PostgreSQL, Kafka, and Redis
-- Connect to PostgreSQL and create database
CREATE DATABASE logisticsdb;
CREATE USER logistics WITH PASSWORD 'secret';
GRANT ALL PRIVILEGES ON DATABASE logisticsdb TO logistics;
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
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
# Using Maven
mvn spring-boot:run
# Using Gradle
./gradlew bootRun
# Using JAR
java -jar target/logistics-service-*.jar
# Set production profile
export SPRING_PROFILES_ACTIVE=prod
# Start with production configuration
java -Dspring.profiles.active=prod -jar logistics-service.jar
-
Application Health:
GET /api/actuator/health
- Database Connectivity: Check via health endpoint
- Redis Status: Monitor via configuration
# Check if service is running
curl http://localhost:8080/api/actuator/health
# Test API endpoints
curl http://localhost:8080/api/v1/deliveries?status=CREATED
- JVM Metrics: Heap usage, GC activity
- Database Connections: HikariCP pool metrics
- API Response Times: Track endpoint performance
- Error Rates: Monitor 4xx/5xx responses
- Application Logs: Console output or specified log file
- Database Logs: PostgreSQL logs for slow queries
- Kafka Logs: Consumer/Producer events
- Startup sequence completion
- Database migration status
- Kafka connection status
- Fraud detection alerts
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
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
Problem: Redis connection timeout
# Check Redis status
redis-cli ping
# Monitor Redis logs
tail -f /var/log/redis/redis-server.log
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
-- Analyze database performance
ANALYZE;
-- Update table statistics
VACUUM ANALYZE logistics.deliveries;
VACUUM ANALYZE logistics.fraud_blacklist;
- Configure logback-spring.xml for log rotation
- Monitor disk space usage
- Archive or delete old logs as needed
# 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
- Use connection pooling (HikariCP configured)
- Implement proper authentication
- Regularly update passwords
- Consider implementing authentication/authorization
- Add rate limiting if needed
- Validate input data thoroughly
- Monitor slow queries
- Add indexes as needed
- Tune HikariCP settings
- Monitor memory usage
- Tune JVM parameters
- Optimize query patterns
- Deploy new version to staging environment
- Run integration tests
- Switch traffic to new instance
- Monitor performance and rollback if needed
- Update one instance at a time
- Verify health before proceeding
- Continue with remaining instances
# Graceful shutdown
kill -TERM <PID>
# Force restart if needed
kill -KILL <PID>
# Restart service
java -jar logistics-service.jar
- Stop application
- Restore from backup
- Run any necessary migrations
- Restart application
- Stop current version
- Deploy previous stable version
- Verify functionality
- Monitor for any issues
- Development Team: [team-email]
- Database Administrator: [dba-email]
- On-Call Support: [oncall-contact]
- Documentation: [wiki-url]