Part 7: Testing, Performance, and Production Deployment

The Database Index Disaster

October 2022. We launched our new gRPC order service to production. Initial load tests showed great results: 2,000 requests/second, 50ms average latency. We celebrated.

Day 3 of production: The service started timing out. Latency spiked to 15 seconds. Orders were failing. Database CPU hit 100%. After 4 hours of desperate debugging, we found the issue: no database indexes on the orders table. Our test data had 1,000 orders. Production had 500,000 orders.

That oversight cost approximately $80,000 in lost revenue, emergency infrastructure scaling, and remediation work. This part covers everything about testing, performance optimization, and production deployment—lessons learned from managing 23 gRPC services in production.

Testing Strategy

Testing Pyramid for gRPC

        /\
       /  \    E2E Tests (5%)
      /____\
     /      \  Integration Tests (25%)
    /________\
   /          \ Unit Tests (70%)
  /______________\

Unit Testing

Setting Up Jest

Repository Layer Tests

Service Layer Tests

Integration Testing

gRPC Server Testing with TestContainers

Load Testing with k6

k6 Script for gRPC

Run Load Test

Performance Optimization

1. Connection Pooling

2. Database Query Optimization

3. Caching Strategy

Production Deployment

Docker Configuration

Docker Compose

Kubernetes Deployment

GitHub Actions CI/CD

Monitoring and Observability

Prometheus Metrics

Health Check Implementation

Key Takeaways

  1. Test Pyramid: 70% unit, 25% integration, 5% E2E

  2. Database Indexes: Critical for production performance

  3. Load Testing: Test with production-like data volumes

  4. Connection Pooling: Reuse connections for better performance

  5. Caching: Redis for frequently accessed data

  6. Monitoring: Prometheus metrics + health checks

  7. CI/CD: Automated testing and deployment

My $80,000 Lesson: Always test with production-scale data. 1,000 records in test vs 500,000 in production makes all the difference.


Series Navigation: gRPC 101 Series

Last updated