Skip to content

Reliability Features

mik includes production-ready reliability features out of the box.

Prevents cascading failures by stopping requests to failing handlers.

  1. Closed - Normal operation, requests pass through
  2. Open - Handler is failing, requests rejected immediately
  3. Half-Open - Testing if handler recovered

Circuit breaker is enabled by default with sensible defaults:

SettingDefaultDescription
Failure threshold5Failures before opening
Recovery timeout30sTime before testing recovery
Half-open max requests3Test requests in half-open
HTTP/1.1 503 Service Unavailable
Retry-After: 30
Content-Type: application/json
{
"type": "urn:mik:error:circuit-open",
"title": "Service Unavailable",
"status": 503,
"detail": "Circuit breaker is open for module: auth"
}

Each WASM module has its own circuit breaker:

A failure in auth.wasm doesn’t affect orders.wasm.

Prevents resource exhaustion from too many requests.

  1. Global limit - Max concurrent requests across all handlers
  2. Per-module limit - Max concurrent requests per handler
[server]
max_concurrent_requests = 1000 # Global limit
max_per_module_requests = 10 # Per-handler limit
HTTP/1.1 503 Service Unavailable
Retry-After: 1
Content-Type: application/json
{
"type": "urn:mik:error:rate-limited",
"title": "Service Unavailable",
"status": 503,
"detail": "Module auth is overloaded"
}

Prevents a slow handler from consuming all resources:

Caches compiled WASM modules for faster cold starts.

[server]
cache_size = 100 # Max cached modules
max_cache_mb = 256 # Max cache size in MB
  1. First request compiles WASM → caches result
  2. Subsequent requests use cached module
  3. LRU eviction when cache is full

Available via health endpoint:

Terminal window
curl http://localhost:3000/health
{
"status": "ready",
"cache_size": 5,
"cache_capacity": 100,
"cache_bytes": 1048576,
"total_requests": 1000
}

Prevents runaway handlers from blocking resources.

[server]
execution_timeout_secs = 30 # Max execution time per request
HTTP/1.1 504 Gateway Timeout
Content-Type: application/json
{
"type": "urn:mik:error:timeout",
"title": "Gateway Timeout",
"status": 504,
"detail": "Handler execution timed out"
}

Prevents memory exhaustion from large request bodies.

[server]
max_body_size_mb = 10 # Max body size in MB
HTTP/1.1 413 Payload Too Large
Content-Type: application/json
{
"type": "urn:mik:error:payload-too-large",
"title": "Payload Too Large",
"status": 413,
"detail": "Request body exceeds 10MB limit"
}

Handles SIGTERM/SIGINT signals gracefully:

  1. Stops accepting new connections
  2. Waits for in-flight requests to complete
  3. Closes connections cleanly
  4. Exits with code 0
Terminal window
# Send shutdown signal (Ctrl+C or)
kill -TERM $(pgrep mik)
# Logs:
# Received shutdown signal, draining connections...
# All connections drained, shutting down

Built-in health endpoint for load balancers:

Terminal window
curl http://localhost:3000/health
{
"status": "ready",
"timestamp": "2025-01-01T00:00:00Z",
"cache_size": 5,
"cache_capacity": 100,
"total_requests": 1000
}
  1. Monitor circuit breaker state - Log when circuits open/close
  2. Tune per-module limits - Based on handler complexity
  3. Set appropriate timeouts - Balance user experience vs resource usage
  4. Use health checks - For load balancer integration
  5. Size cache appropriately - Based on module count and sizes