← Back to Use Cases
OPERATIONAL CONTROL

Safeguarded Maintenance Switches

Centralize "maintenance mode/on-call owner/traffic-drain target" flags per service; updates require master token, reads stay public.

The Problem

You need to coordinate operational state across multiple services: maintenance mode flags, current on-call engineer, traffic routing targets, or feature rollout percentages. These need to be readable by all services but updatable only by authorized operators.

Hardcoding these values requires redeployment. Using environment variables means restarting services. You need real-time, centralized control.

The WrenDB Solution

Store operational flags in a public-read stash. Services poll the flags without authentication. Only operators with the master token can update them. No database, no config management system, just HTTP.

Step-by-Step Guide

1

Create your operational stash

Set up a central stash for operational flags:

Terminal
# Create stash for operational flags
curl -X POST https://wrendb.com/api/stash

{
  "stash_id": "ops123...",
  "master_token": "token-secure456...",
  "message": "Save this token securely..."
}

# Initialize flags (requires token)
curl -X POST https://wrendb.com/api/item/ops123.../maintenance-mode \
  -d "false"

curl -X POST https://wrendb.com/api/item/ops123.../on-call-engineer \
  -d "alice@company.com"

curl -X POST https://wrendb.com/api/item/ops123.../traffic-target \
  -d "production-cluster-a"
2

Services read flags (no auth needed)

Your services check flags before handling requests:

service.py
import requests
import time
from flask import Flask, jsonify

app = Flask(__name__)

STASH_ID = "ops123..."
FLAGS_CACHE = {}
CACHE_TTL = 30  # seconds
LAST_FETCH = 0

def get_flag(flag_name):
    """Get operational flag with caching"""
    global LAST_FETCH, FLAGS_CACHE

    if time.time() - LAST_FETCH > CACHE_TTL:
        try:
            # No auth needed - public read
            response = requests.get(
                f"https://wrendb.com/api/item/{STASH_ID}/{flag_name}",
                timeout=2
            )
            if response.status_code == 200:
                FLAGS_CACHE[flag_name] = response.text
                LAST_FETCH = time.time()
        except Exception:
            pass  # Use cached value on error

    return FLAGS_CACHE.get(flag_name)

@app.route("/api/data")
def handle_request():
    # Check maintenance mode
    if get_flag("maintenance-mode") == "true":
        return jsonify({"error": "Service in maintenance"}), 503

    # Normal processing
    return jsonify({"status": "ok"})
3

Operators update flags (auth required)

Build a simple CLI tool for operators:

ops-cli.sh
#!/bin/bash

STASH_ID="ops123..."
TOKEN="$OPS_TOKEN"  # Set in environment

case "$1" in
  maintenance-on)
    curl -X PUT "https://wrendb.com/api/item/$STASH_ID/maintenance-mode" \
      -H "Authorization: Bearer $TOKEN" \
      -d "true"
    echo "✅ Maintenance mode enabled"
    ;;

  maintenance-off)
    curl -X PUT "https://wrendb.com/api/item/$STASH_ID/maintenance-mode" \
      -H "Authorization: Bearer $TOKEN" \
      -d "false"
    echo "✅ Maintenance mode disabled"
    ;;

  set-oncall)
    curl -X PUT "https://wrendb.com/api/item/$STASH_ID/on-call-engineer" \
      -H "Authorization: Bearer $TOKEN" \
      -d "$2"
    echo "✅ On-call set to: $2"
    ;;

  route-traffic)
    curl -X PUT "https://wrendb.com/api/item/$STASH_ID/traffic-target" \
      -H "Authorization: Bearer $TOKEN" \
      -d "$2"
    echo "✅ Traffic routed to: $2"
    ;;

  status)
    echo "Current operational state:"
    echo "Maintenance: $(curl -s https://wrendb.com/api/item/$STASH_ID/maintenance-mode)"
    echo "On-call: $(curl -s https://wrendb.com/api/item/$STASH_ID/on-call-engineer)"
    echo "Traffic: $(curl -s https://wrendb.com/api/item/$STASH_ID/traffic-target)"
    ;;

  *)
    echo "Usage: ops-cli {maintenance-on|maintenance-off|set-oncall|route-traffic|status}"
    ;;
esac

Usage Examples

Terminal
# Enable maintenance mode
./ops-cli.sh maintenance-on

# Update on-call engineer
./ops-cli.sh set-oncall bob@company.com

# Route traffic to different cluster
./ops-cli.sh route-traffic production-cluster-b

# Check current status (no auth needed)
./ops-cli.sh status

Why This Works

  • Instant propagation - No deployments or service restarts needed
  • Secure updates - Only master token holders can change flags
  • Public reads - Services don't need credentials to check state
  • Simple caching - Services cache values with short TTL for performance

Related Use Cases

Config Sharing - Share environment configs and feature flags One-click Approvals - Time-limited approval workflows