KatInterview

HTTP API Design for Binomial Coefficient Sequences

System DesignModel answer
MediumModel answerSystem Designapi-designhttpvalidation

Last updated

Design a clean HTTP API that delivers row-by-row binomial coefficients, covering endpoint structure, validation, error contracts, and numeric limits.

You're designing a public HTTP API that serves sequences of binomial coefficients arranged in triangular form (each row n contains the coefficients C(n, 0) through C(n, n)).

The service should return structured numeric data only—no formatting, padding, or visual layout. Clients are responsible for rendering and presentation.

Specify:

  1. Endpoint design – HTTP method, path, and parameters
  2. Response schema – JSON structure with concrete examples
  3. Validation rules – parameter types, ranges, and rejection criteria
  4. Error handling – status codes, error envelope format, and specific error cases
  5. Practical constraints – maximum input size with technical justification (consider both client numeric precision and server resource limits)
  6. Non-functional concerns – caching, rate limiting, and any other production-readiness considerations

Provide a model answer that demonstrates systematic API design thinking, grounded in HTTP semantics and real-world numeric constraints.

Hints

Hint 1

Consider which HTTP method best reflects the operation's semantics—does it mutate state or compute a pure function of its input?

Hint 2

JSON numbers have precision limits in many clients; calculate exactly where IEEE-754 double precision breaks down for the largest coefficient in each row.

Hint 3

Edge cases matter: how should the API handle zero rows, malformed integers, or parameters just beyond the numeric safety boundary?