Interview Prep/Python for DevOps/Automation scripting & CLI design

You must call an internal API that sometimes returns 503 for a few seconds during deploys. Your script fails randomly. Fix it.

BeginnerScenarioAutomation scripting & CLI design
Answer

Situation read → Transient errors; the client should retry with backoff, not fail.

What I'd do →

  1. Use a requests.Session with an HTTPAdapter(max_retries=Retry(total=5, backoff_factor=1, status_forcelist=(502, 503, 504), respect_retry_after_header=True)).
  2. Keep explicit timeouts (timeout=(3, 10)).
  3. Only retry idempotent methods automatically.
  4. Log each retry at WARNING so persistent problems are visible.

Why → A few seconds of backoff absorbs deploy blips without masking real outages, because retries are bounded.

Interview tip → Also suggest the API team fix it with readiness probes and connection draining.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design