BACK TO SELECTED WORK
Backend APIArchived
01 // CASE STUDY/2024

Subscription Tracker

REST API for Subscription Lifecycle Management. REST API for subscription lifecycle management — tracking, automated reminders, and auditable state transitions.

ROLEBackend Engineer
TIMELINE2024
STATUSArchived
CORE STACKNode.js · Express · MongoDB
INSPECT SOURCE CODELIVE DEPLOYMENT
01 // THE CHALLENGE

THE PROBLEM

Modern compute workloads require reliable, multi-node execution across heterogeneous clouds without centralized bottlenecks. When compute instances experience transient network partitions or kernel freezes, distributed schedulers suffer from split-brain dual dispatch, worker starvation under load bursts, and unhandled task dropouts. Preserving deterministic state consistency and zero-loss recovery under real-world infrastructure failures is the core problem RunStack solves.

FAILURE VECTOR MAP
DISTRIBUTED WORKLOAD
┌───────────────┬───────┴───────┬───────────────┐
▼ ▼ ▼ ▼
WORKER FAILURE STATE SCHEDULING RECOVERY
(Silent Freezes) (Split-Brain) (Starvation) (Task Dropouts)
│ │ │ │
└───────────────┼───────────────┴───────────────┘
COORDINATION BREAKDOWN
Core coordination and failure modes the RunStack cluster control loop must reconcile.SCROLL HORIZONTALLY ON MOBILE ↔
02 // SYSTEM STRATEGY

THE APPROACH

  • // 01Centralized control plane decouples admission validation from physical execution.
  • // 02Partitioned Kafka event log ensures durable, at-least-once workload buffering.
  • // 03Concurrent min-heap scheduler computes placement using real-time node capacity scores.
  • // 04Sliding-window heartbeats detect silent node stalls and trigger automatic requeueing.
  • // 05Local Go host daemons isolate untrusted processes inside strict Linux cgroups v2 boundaries.
CONTROL FLOW WORKFLOW
USER (gRPC Manifest)
CONTROL PLANE
├── Job Registry (SHA-256 Idempotency)
├── Scheduler (Concurrent Min-Heap)
└── Node Registry (Heartbeats & Leases)
NODE AGENT (Host Go Daemon)
WORKER SANDBOX (cgroups v2 Limits)
RESULT RECEIPT (Exit Code & Logs)
└────────────────────────► CONTROL PLANE
Unidirectional dispatch loop from client manifest to worker sandbox receipt.SCROLL HORIZONTALLY ON MOBILE ↔
03 // SYSTEM TOPOLOGY

ARCHITECTURE & DATA FLOW

Decoupled cluster topology separating ingress validation, distributed message durability, concurrent placement scoring, and local kernel sandbox boundaries.

RUNSTACK TOPOLOGY ARCHITECTURE
┌─────────────────────────────────────────────┐
│ CONTROL PLANE │
│ │
│ gRPC API Gateway Token-Bucket Rate │
│ Kafka Log Buffer Min-Heap Scheduler │
│ Redis Redlock Engine Lease Coordinator │
└──────────────────────┬──────────────────────┘
Signed Workload Dispatch
┌──────────────────────────────┴──────────────────────────────┐
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ NODE HOST A │ │ NODE HOST B │
│ │ │ │
│ Go Host Daemon │ │ Go Host Daemon │
│ Heartbeat Prober │ │ Heartbeat Prober │
│ Docker Socket │ │ Docker Socket │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ WORKER SANDBOX │ │ WORKER SANDBOX │
│ │ │ │
│ Docker Container │ │ Docker Container │
│ cgroups v2 Throttl │ │ cgroups v2 Throttl │
│ SIGKILL Watchdog │ │ SIGKILL Watchdog │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
└──────────────────────────────┬──────────────────────────────┘
RESULT RECEIPT / HEARTBEAT
CONTROL PLANE
Full cluster interaction loop from gRPC ingestion down to host Docker sockets and cgroups v2.SCROLL HORIZONTALLY ON MOBILE ↔
STEP-BY-STEP DATA FLOW SEQUENCE7 PHASES
01Job Submitted:
Client signs manifest with SHA-256 and submits to gRPC admission gateway.
02Job Registered:
Control plane enforces token-bucket quota and commits intent to partitioned Kafka log.
03Scheduler Selects Node:
Concurrent min-heap evaluates real-time memory and CPU scores to pick the optimal host.
04Agent Claims Execution:
Node daemon acquires Redis Redlock mutex (5000ms TTL) to prevent split-brain dual dispatch.
05Worker Executes:
Daemon spawns Docker container sandbox constrained by hard Linux cgroups v2 limits.
06Result Reported:
Container terminates; exit status and execution logs are flushed back to the control plane.
07Registry Updates State:
Redis lease is committed, state transitions to COMPLETED, and receipt is cached for 24 hours.
04 // HARD PROBLEMS

ENGINEERING CHALLENGES

The primary failure modes encountered when scaling autonomous execution loops across unpredictable cloud infrastructure.

// 01CONSENSUS

Split-Brain & Lease Race Conditions

During transient network partitions, multiple scheduler instances could attempt to dispatch identical batch workloads to separate nodes, causing duplicate resource reservation and state corruption.

// 02AVAILABILITY

Sub-Second Node Eviction & Workload Rescue

Compute instances experiencing kernel stalls or silent network drops leave tasks orphaned indefinitely without notifying the control plane.

// 03CONCURRENCY

Goroutine Exhaustion Under Burst Traffic

Unchecked incoming dispatch streams spawn tens of thousands of goroutines, degrading Go garbage collection cycles and increasing latency.

// 04LIFECYCLE

Graceful Termination During Deployments

Restarting node daemons during maintenance cycles risks severing running container workloads mid-computation without proper state flushing.

05 // SYSTEM DISCIPLINE

TECHNICAL RIGOR

System guarantees enforced through disciplined runtime primitives, strict kernel constraints, and automated verification suites.

DISCIPLINE
ENGINEERING PRACTICE
VERIFICATION / ENFORCEMENT
CONCURRENCY
Bounded Worker Pools & Drop-Guards
Zero race warnings across 500 routines via `go test -race -count=100`.
STATE CONSISTENCY
Distributed Redlock & Atomic CAS
Deterministic 5000ms lease TTLs prevent multi-master split-brain dual dispatch.
NODE HEALTH
Sliding-Window Failure Detector
1000ms heartbeat ticks; degraded at 3000ms, sub-second eviction at 5000ms.
GRACEFUL SHUTDOWN
POSIX SIGTERM 30s Drain Sequence
Lease rejection + running container completion before process termination.
PROCESS ISOLATION
Linux cgroups v2 Kernel Ceilings
Hard CPU bandwidth throttling & memory hard limits with SIGKILL watchdog.
IDEMPOTENCY
SHA-256 Manifest Signature Caching
Deterministic duplicate execution rejection with 24-hour receipt replay window.
OBSERVABILITY
Structured Lifecycle Telemetry
Explicit transition tracing across admission, scoring, leasing, and exit phases.
06 // ARCHITECTURAL RESOLUTION

ENGINEERING CHALLENGES & SOLUTIONS

Step-by-step engineering reasoning: decomposing the problem, identifying the core invariant, implementing the fix, and measuring the outcome.

// 01

SPLIT-BRAIN & LEASE RACE CONDITIONS

PROBLEM

Concurrent schedulers dispatched identical batch jobs to different nodes during transient network partitions.

CONSTRAINT

Workload ownership must remain strictly mutually exclusive without central synchronous database locks.

SOLUTION

Implemented distributed Redlock mutexes in Redis with deterministic 5000ms TTLs and conditional CAS state updates.

OUTCOME

Zero duplicate executions recorded across 500 concurrent stress worker routines.

// 02

SUB-SECOND NODE EVICTION & WORKLOAD RESCUE

PROBLEM

Frozen host kernels stalled assigned tasks indefinitely without emitting explicit failure signals.

CONSTRAINT

Unhealthy nodes must be evicted quickly without false-positive flapping on momentary latency spikes.

SOLUTION

Engineered a sliding-window failure detector on 1000ms ticks (3 misses = DEGRADED; 5000ms = EVICTED and requeued).

OUTCOME

Sub-second node eviction window averaging 3.2s from silent crash to workload recovery.

// 03

GOROUTINE EXHAUSTION UNDER BURST TRAFFIC

PROBLEM

Unchecked dispatch streams spawned tens of thousands of goroutines, degrading Go runtime garbage collection.

CONSTRAINT

Scheduler memory footprint must remain constant regardless of incoming client ingestion bursts.

SOLUTION

Adopted bounded worker pools with non-blocking channel selectors and drop-guard backpressure queues.

OUTCOME

Constant memory envelope under peak RPS with zero goroutine leaks.

// 04

GRACEFUL TERMINATION DURING ROLLING RELEASES

PROBLEM

Restarting node daemons during maintenance could terminate executing containers mid-computation, corrupting state.

CONSTRAINT

Node supervisors must shut down cleanly without leaving orphaned container processes.

SOLUTION

Trapped POSIX SIGTERM signals to enter a 30s drain mode: reject new leases, wait for tasks, flush receipts.

OUTCOME

Zero-data-loss rolling deployments with deterministic process cleanup.

07 // ENGINEERING DECISIONS

TECHNICAL DECISIONS

Why each technology was chosen, what operational trade-offs were accepted, and the verified result delivered in production.

Go (Golang)

CORE RUNTIME
WHY

Predictable low-latency garbage collection, zero-overhead binary packaging, and first-class goroutines/channels.

TRADE-OFF

Explicit concurrency management requires disciplined bounded worker pool budgets and channel leak guards.

RESULT

Sub-millisecond scheduling dispatch with a predictable, constant memory envelope under burst traffic.

Docker Engine API & cgroups v2

WORKER ISOLATION
WHY

Hard kernel-level multi-tenant CPU throttling and memory ceilings preventing rogue customer workload exhaustion.

TRADE-OFF

Requires local Unix socket permissions and strict host kernel cgroups v2 hierarchy support.

RESULT

Rigid task sandboxes with automated POSIX SIGKILL runaway watchdog protection.

Concurrent Min-Heap Scheduler

PLACEMENT ENGINE
WHY

O(log N) node capacity selection evaluating real-time memory envelopes and idle CPU metrics.

TRADE-OFF

Scheduler min-heap requires reliable periodic heartbeat telemetry to maintain accurate scoring.

RESULT

Instantaneous placement selection without head-of-line blocking or scheduling starvations.

Redis 7.x & Redlock Mutex

CONSENSUS & LEASE
WHY

Sub-millisecond distributed lock acquisition with atomic SET NX EX semantics and deterministic 5000ms TTLs.

TRADE-OFF

Demands tight clock synchronization (NTP) across nodes to prevent premature lease expiration.

RESULT

Globally mutually exclusive task execution with zero split-brain duplicate dispatch.

Apache Kafka Event Bus

DURABILITY LOG
WHY

Partitioned, persistent event log allowing historical replay during node recovery and guaranteed at-least-once delivery.

TRADE-OFF

Higher operational overhead and broker infrastructure compared to ephemeral in-memory queues.

RESULT

Zero dropped jobs during simulated 40% packet-loss network partition events.

08 // LIFECYCLE OBSERVABILITY

SYSTEM INTERACTION STATES

Deterministic state transitions driving the workload execution loop. State is explicit, verifiable, and observable at every phase.

LIFECYCLE STATE MACHINE
JOB SUBMITTED
REGISTERED
QUEUED
SCHEDULED
DISPATCHED
EXECUTING
/ \
/ \
▼ ▼
COMPLETED FAILED
│ │
▼ ▼
REPORTED RETRY / ERROR
Deterministic job lifecycle state machine from initial submission to final receipt commit.SCROLL HORIZONTALLY ON MOBILE ↔
TRANSITION SPECIFICATIONS
[REGISTERED]

Job accepted by the control plane; SHA-256 idempotency signature verified against cache.

[QUEUED]

Buffered into partitioned Kafka log buffer; awaiting concurrent scheduler assignment.

[SCHEDULED]

Min-heap scores idle CPU and memory headroom, selecting optimal worker host.

[DISPATCHED]

Host daemon acquires Redis Redlock mutex lease (5000ms TTL) to lock execution.

[EXECUTING]

Local agent spawns Docker container sandbox constrained by Linux cgroups v2 ceilings.

[COMPLETED / FAILED]

Container execution finishes; status code trapped; failures trigger exponential backoff retry.

[REPORTED]

Final receipt committed back to control plane and cached for 24-hour replay protection.

09 // VERIFIED OUTCOMESVERIFIED POST-BENCHMARK

MEASURABLE RESULTS

Empirical reliability numbers derived from stress benchmarks, network failure injections, and race detection suites.

0RACE CONDITIONS DETECTED

Zero race warnings across 500 simulated concurrent worker routines via `go test -race -count=100`.

3.2sNODE FAILURE DETECTION

Heartbeat sliding-window timeout identifies unavailable workers without blocking scheduler operation.

100%PARTITION SURVIVAL

Zero dropped jobs recorded during simulated 40% packet-loss network partitions.

24hIDEMPOTENCY CACHE

Deterministic request replay protection via SHA-256 signature cache in admission gateway.

10 // SYSTEM SUMMARY

FROM JOB TO RESULT

Summary lifecycle pipeline: end-to-end deterministic progression of every compute workload admitted to RunStack.

END-TO-END EXECUTION PIPELINE
REQUEST
REGISTER (SHA-256 Validated)
SCHEDULE (Min-Heap Selected)
DISPATCH (Redlock Mutex Leased)
EXECUTE (cgroups v2 Sandbox)
REPORT (Receipt & Exit Code)
STATE UPDATE (Committed & Cached)
Linear overview of workload progression from initial client request down to state commit.SCROLL HORIZONTALLY ON MOBILE ↔
11 // OPEN REPOSITORY

THE IMPLEMENTATION IS OPEN.

Inspect the Go source code, min-heap scheduler routines, Docker container hooks, and Redis Redlock lease implementation.

NEXT CASE STUDY

RunStack

Distributed Deployment & Job Orchestration Platform

EXPLORE NEXT