Write a script that reads a JSON file of services and checks each one's health endpoint concurrently.

IntermediateHands-onPython for DevOps
Answer
import json
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests

with open("services.json") as f:
    services = json.load(f)   # [{"name": "api", "url": "https://.../health"}, ...]

def check(svc):
    try:
        r = requests.get(svc["url"], timeout=5)
        return svc["name"], r.status_code, r.elapsed.total_seconds()
    except requests.RequestException as e:
        return svc["name"], "DOWN", str(e)[:60]

with ThreadPoolExecutor(max_workers=20) as pool:
    for fut in as_completed(pool.submit(check, s) for s in services):
        print(*fut.result())

Key trick → Health checks are I/O-bound, so threads give a big speed-up despite the GIL. as_completed prints results as they arrive instead of in submit order.

All Real-World Interview questions Roadmap: Interview readiness

More on Python for DevOps