Kubernetes Migration: From Lambda to a Cost-Optimized K8s Cluster

Introduction This article documents our journey migrating from AWS Lambda to a self-managed Kubernetes cluster to handle high-concurrency API requests. We'll walk through our motivation, infrastructure choices, implementation details, and most importantly - the performance results that validated our decision. Why Migrate From Lambda? Our original architecture used AWS Lambda behind API Gateway, but we encountered significant limitations: Concurrency Limitations: Our Lambda-based service was unable to handle concurrent executions exceeding 1000 users Poor Performance Under Load: Load testing revealed significant degradation and high failure rates at scale Cost Optimization: We needed to optimize our cost-per-user-served metric Performance Comparison The most compelling argument for our migration comes from the load test results comparing our previous Lambda setup with our new Kubernetes infrastructure options: Key Findings: HTTPS Nginx setup achieved 100% success rate with the lowest average latency (7468ms) at 1100 concurrent users DNS Round-Robin Load Balancer averaged ~89% success rate with varying latency across pods (from 12676ms to 53028ms) NodePort service averaged ~89% success rate with similar latency variance Lambda performed poorly with only 43.48% success rate despite being tested at a lower concurrency (800 users) The visualization clearly demonstrates that our properly configured Nginx + Kubernetes setup significantly outperforms the Lambda architecture, particularly in handling burst traffic and maintaining high success rates.

Apr 4, 2025 - 11:45
 0
Kubernetes Migration: From Lambda to a Cost-Optimized K8s Cluster

Introduction

This article documents our journey migrating from AWS Lambda to a self-managed Kubernetes cluster to handle high-concurrency API requests. We'll walk through our motivation, infrastructure choices, implementation details, and most importantly - the performance results that validated our decision.

Why Migrate From Lambda?

Our original architecture used AWS Lambda behind API Gateway, but we encountered significant limitations:

  1. Concurrency Limitations: Our Lambda-based service was unable to handle concurrent executions exceeding 1000 users
  2. Poor Performance Under Load: Load testing revealed significant degradation and high failure rates at scale
  3. Cost Optimization: We needed to optimize our cost-per-user-served metric

Performance Comparison

The most compelling argument for our migration comes from the load test results comparing our previous Lambda setup with our new Kubernetes infrastructure options:

Load Test Comparison Graphs

Key Findings:

  • HTTPS Nginx setup achieved 100% success rate with the lowest average latency (7468ms) at 1100 concurrent users
  • DNS Round-Robin Load Balancer averaged ~89% success rate with varying latency across pods (from 12676ms to 53028ms)
  • NodePort service averaged ~89% success rate with similar latency variance
  • Lambda performed poorly with only 43.48% success rate despite being tested at a lower concurrency (800 users)

The visualization clearly demonstrates that our properly configured Nginx + Kubernetes setup significantly outperforms the Lambda architecture, particularly in handling burst traffic and maintaining high success rates.