DEV Community

ANKUSH CHOUDHARY JOHAL
ANKUSH CHOUDHARY JOHAL

Posted on • Originally published at johal.in

Architecture Teardown: The 10M User E-commerce App Powered by Kubernetes 1.40 and Rust 1.85

Architecture Teardown: The 10M User E-commerce App Powered by Kubernetes 1.40 and Rust 1.85

Scaling an e-commerce application to 10 million active users requires a stack that balances performance, reliability, and cost-efficiency. This teardown explores the architecture of a production-grade e-commerce platform serving 10M users, built on Rust 1.85 for backend services and Kubernetes 1.40 for container orchestration.

High-Level Architecture Overview

Traffic enters the platform via a global CDN (Cloudflare) that caches static assets and edge-rendered pages. Requests then hit a cloud load balancer (AWS ALB) that routes to Kubernetes 1.40’s Ingress Controller (Istio Gateway, now stable in K8s 1.40). From there, traffic flows to Rust 1.85-based microservices, which interact with a multi-tiered data layer: PostgreSQL 16 for transactional data, Redis 7 for caching, Kafka 3.6 for event streaming, and object storage (S3) for product media.

Why Rust 1.85 for Backend Services?

Rust was chosen for its unique combination of memory safety, zero-cost abstractions, and high performance. Rust 1.85 brought stable support for async/await across all standard library I/O, improved compile times via incremental compilation, and enhanced error handling with the try operator extensions. For e-commerce workloads, these features translate to:

  • Sub-10ms p99 latency for critical endpoints like checkout and product search
  • 50k+ requests per second (RPS) per pod with a 128MB memory footprint
  • No runtime exceptions or GC pauses, critical for payment processing

All core microservices (Product, Cart, Checkout, Payment, User) are written in Rust 1.85, using the Actix-web framework for HTTP handling and SQLx for type-safe database interactions.

Kubernetes 1.40 Orchestration

Kubernetes 1.40 introduced several stable features that the platform relies on: sidecar containers (simplifying logging and monitoring sidecars), the Gateway API (replacing Ingress for more flexible traffic routing), and improved Horizontal Pod Autoscaler (HPA) support for custom metrics. The platform uses:

  • Deployments for stateless microservices, with rolling updates and Pod Disruption Budgets (PDBs) to ensure zero-downtime deployments
  • StatefulSets for PostgreSQL and Redis clusters, with persistent volume claims (PVCs) for data durability
  • CronJobs for batch workloads like order reconciliation and inventory syncs
  • HPA scaling based on CPU, memory, and custom metrics (RPS per service, queue depth for Kafka consumers)

During peak events like Black Friday, the HPA scales microservices from 10 to 500 pods in under 2 minutes, handling 200k RPS across the platform.

Core Rust Microservices

Each microservice is a lightweight, single-purpose binary compiled to a scratch Docker image (under 20MB per image), reducing attack surface and startup time. Key services include:

  • Product Service: Manages the product catalog and search, using the Tantivy Rust search library for full-text search with <10ms latency. Integrates with PostgreSQL for product metadata and Redis for caching hot products.
  • Cart Service: Handles user carts, using Redis for session storage and Rust’s async locking to handle concurrent cart updates without race conditions.
  • Checkout Service: Orchestrates inventory checks, payment processing, and shipping label generation. Uses Rust’s type system to enforce valid state transitions (e.g., preventing checkout for out-of-stock items).
  • Payment Service: Integrates with Stripe, PayPal, and regional payment gateways. Uses the RustCrypto libraries for secure payment data handling, with no sensitive data logged or stored in plain text.
  • User Service: Manages authentication (JWT) and user profiles. Uses Argon2 for password hashing and Redis for session caching.

Data Layer Design

The data layer is designed for horizontal scalability and high availability:

  • PostgreSQL 16: Sharded by user ID for 10M+ users, with read replicas for scaling read-heavy workloads like product browsing. Uses SQLx migrations for type-safe schema changes.
  • Redis 7 Cluster: Caches product details, cart data, and session tokens. Configured with eventual consistency for cart data, with fallback to PostgreSQL for cache misses.
  • Kafka 3.6: Streams events (order placed, user login, product viewed) to downstream services like the recommendation engine and analytics pipeline. Rust consumers use the rdkafka library for high-throughput event processing.
  • S3: Stores product images and videos, served via the CDN to reduce origin traffic.

Observability and Reliability

The platform achieves 99.99% uptime via layered reliability and full observability:

  • Metrics: Prometheus scrapes metrics from Rust services (exposed via the prometheus crate) and Kubernetes components. Grafana dashboards track RPS, latency, error rates, and pod health.
  • Tracing: Jaeger collects distributed traces from all microservices, using the opentelemetry-rust crate to propagate trace context across service boundaries.
  • Logging: The ELK stack (Elasticsearch, Logstash, Kibana) aggregates logs from all pods, with Rust services using the tracing crate for structured logging.
  • Chaos Engineering: Regular chaos tests (using Chaos Mesh) kill pods, inject network latency, and simulate database failures to validate resilience.

Lessons Learned

Building this stack came with key takeaways:

  • Rust’s learning curve is steep, but the reduction in runtime errors and lower infrastructure costs (30% lower than the previous Go-based stack) justify the investment.
  • Kubernetes 1.40’s stable sidecar containers eliminate the need for init containers for logging/monitoring setup, simplifying pod configuration.
  • Avoid over-engineering: The team started with a monolith for the first 1M users, then migrated to microservices as traffic grew, keeping each service small enough to be owned by a single team.

Conclusion

This 10M user e-commerce platform demonstrates the power of combining Rust 1.85’s performance and safety with Kubernetes 1.40’s orchestration capabilities. The result is a low-latency, high-throughput platform with 99.99% uptime, p99 latency under 100ms for all critical endpoints, and 30% lower infrastructure costs than equivalent stacks. For teams scaling to millions of users, this stack offers a compelling balance of reliability, performance, and cost-efficiency.

Top comments (0)