Your question is Common SaaS Problem to Production. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Headway's platform receives webhook callbacks from an insurance eligibility verification vendor whenever a client's coverage check finishes. The vendor retries the same webhook if it doesn't get a 200 response within 3 seconds. Below is the handler a Headway engineer wrote for the FastAPI service that updates the client's coverage status.
from fastapi import FastAPI
import requests
app = FastAPI()
coverage_cache = {}
@app.post("/webhooks/eligibility")
def handle_eligibility(payload: dict):
client_id = payload["client_id"]
status = payload["status"]
coverage_cache[client_id] = status
if status == "verified":
requests.post("https://internal.headway.co/notify", json={
"client_id": client_id,"message": "Your coverage has been verified!",
})
update_database(client_id, status)
return {"ok": True}
def update_database(client_id, status):
db.execute(f"UPDATE clients SET coverage_status = '{status}' WHERE id = {client_id}")
Work through, in writing, what happens the first time this handles a real webhook, what happens if the vendor retries it, and how you'd redesign it to run safely and correctly in production.