Interview Prep/Shell Scripting/Scenarios: text processing and scheduling decisions

A cron job on 500 servers uploads metrics to an API at `0 * * * *`. The API rate-limits and many uploads fail. Fix it.

IntermediateScenarioScenarios: text processing and scheduling decisions
Answer

Situation read → Thundering herd: every host fires at exactly the same second.

What I'd do →

  1. With systemd timers: RandomizedDelaySec=15min and, on recent systemd, FixedRandomDelay=true so each host gets a stable offset.
  2. With cron: a stable per-host delay derived from the hostname:
    delay=$(( $(hostname | cksum | cut -d' ' -f1) % 900 ))
    sleep "$delay"
    
  3. Add retries with exponential backoff and jitter on HTTP 429.
  4. Ask whether pull-based collection (Prometheus scraping) fits better than push.

Why → Spreading 500 requests across 15 minutes turns a spike into a trickle.

Interview tip → Mention a stable offset over a random one, so each host's run time is predictable for debugging.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions