Lab 15: Capstone — Production Platform

Time: 90 minutes | Level: Architect | Docker: docker run -it --rm node:20-alpine sh

This capstone integrates everything from Labs 01–14 into a production-grade Node.js platform: gRPC API, worker thread pool, LRU cache, circuit breaker, AES-GCM encryption, AsyncLocalStorage tracing, OpenTelemetry spans, and cluster mode — with a complete test suite.


Architecture Overview

Cluster (2 workers)

└── Worker Process

    ├── gRPC Server (@grpc/grpc-js)
    │     └── Interceptors: auth, logging, tracing

    ├── Worker Thread Pool (SharedArrayBuffer)
    │     └── CPU-bound: encrypt, hash, compute

    ├── LRU Cache (in-process)
    │     └── → Redis (ioredis, mock in tests)

    ├── Circuit Breaker (opossum)
    │     └── Wraps external service calls

    ├── AsyncLocalStorage
    │     └── Request context: traceId, userId, spans

    └── OpenTelemetry
          └── TracerProvider → InMemorySpanExporter (test) / OTLP (prod)

Step 1: Project Setup


Step 2: Proto Definition


Step 3: LRU Cache Module


Step 4: Worker Thread — CPU Tasks


Step 5: Worker Thread Pool


Step 6: Platform Service Implementation


Step 7: gRPC Server


Step 8: Complete Test Suite

Run tests:

📸 Verified Output (running grpc + workers inline):

💡 Full capstone test suite runs with: npx vitest run --reporter=verbose


Step 8b: Running Everything

Cluster entry:


Summary — Capstone Integration

Component
Lab
Technology

V8 optimization

01

Monomorphic patterns, TypedArrays

Event loop

02

AsyncLocalStorage request context

Memory

03

LRU cache with TTL, no leaks

Worker threads

04

SharedArrayBuffer, thread pool

gRPC API

11

@grpc/grpc-js, proto-loader

Streams

06

Pipeline for data processing

Cluster

07

2-worker cluster, rolling restart

Profiling

08

PerformanceObserver, latency tracking

Security

09

AES-GCM encrypt, Ed25519 sign

Modules

10

ESM throughout

Caching

12

LRU + Redis (mock) + SWR

Microservices

13

Circuit breaker, retry

Observability

14

OpenTelemetry spans, metrics

Capstone

15

All components integrated

Last updated