Review and fix a GET events endpoint
Company: StubHub
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
You are given a GET /events endpoint that queries events from a database and, for each event, loads the related transactions for subsequent processing. Review the implementation and identify problems across: readability (duplicate code, poor naming/structure, unclear responsibilities), security (risk of SQL injection, missing input validation, authentication/authorization gaps, unsafe error handling, PII exposure), and performance (N+1 queries, excessive round trips, lack of batching/joins, missing indexes, no pagination, lack of caching). Propose concrete fixes: refactor to eliminate duplication and clarify layers, add parameterized queries and schema-based validation, enforce authN/authZ and least-privilege access, implement pagination and proper status codes, batch or prefetch related data to avoid N+1, add appropriate indexes, and add API caching (ETag/Last-Modified, Cache-Control) where safe. Outline a test plan covering unit/integration tests, security tests (injection, auth), and performance tests (query counts, latency, load).
Quick Answer: This question evaluates proficiency in backend API and system design, covering API review, relational data access patterns, security considerations, performance analysis, maintainability, and test planning.