Your question is Debug an Issue in Code. 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).
You're interviewing for a Software Engineer role on a team that owns GitHub's webhook delivery pipeline, the service that takes repository events (pushes, issues, releases) and forwards them to downstream consumers.
A teammate wrote the event handler below. It passed code review, shipped, and now the on-call channel is reporting that some repositories stop receiving certain events after a while, and that a handful of deliveries are being retried far more than expected.
import hmac
import hashlib
MAX_RETRIES = 3
ALLOWED_EVENTS = "push pull_request issues release"
def verify_signature(payload_body, secret, github_signature):
expected = "sha256=" + hmac.new(secret.encode(), payload_body, hashlib.sha256).hexdigest()
return expected == github_signature
def process_event(payload, seen_ids=[]):
event_id = payload.get("delivery_id")
event_type = payload.get("event_type", "")
if event_id in seen_ids:
return "duplicate"
seen_ids.append(event_id)
if event_type not in ALLOWED_EVENTS:
return "ignored"
retries = 0
while retries <= MAX_RETRIES:
try:
forward_to_queue(payload)
return "delivered"
except Exception:
retries += 1
return "failed"
def forward_to_queue(payload):
queue_client.publish("repo-events", payload)
Walk through how you would debug this: what would you look for first, what do you think is actually going wrong, and how would you fix each issue you find. Explain your reasoning rather than just naming the bugs.