2dbi

Design a 2-Day Delivery Eligibility API

viaLeetCode

Problem Design an API that answers: can this product reach this destination pincode within 2 days? Cover the core eligibility logic, data model, extensibility, and failure handling.

Requirements

  • GET /eligibility?productId&pincode → { eligible, promiseDate, serviceLevel }; batch variant for listing pages.
  • Eligibility = product in stock at a warehouse whose transit time to the pincode ≤ 2 days (courier serviceability + capacity included).

Core design

  • Model: Warehouse(id, location, pincodes served), PincodeZone(pincode → zone), TransitTime(warehouse_id, zone, courier, days), Inventory(product_id, warehouse_id, qty), ServiceLevel enum (2-day, next-day…) so new promises are data, not code.
  • EligibilityService: resolve pincode → zone; find warehouses with stock; min transit time across (warehouse, courier); compare against the service level. Strategy interface per courier's serviceability rules; precomputed (warehouse, zone) transit matrix rather than per-request distance math.
  • Extensibility: multiple regions = zone hierarchies + region-scoped transit tables; cutoff times (order-by-2pm) folded into promise computation.

Discussion points

  • Latency: this API sits on product pages → cache (product, pincode-zone) results with short TTL; precompute zone-level eligibility; batch lookups.
  • Failure handling: courier-API/dependency down → serve cached/estimated data with a degraded flag, timeouts + circuit breaker, never block the page.
  • Correctness drift: inventory changes between page view and order → re-verify at checkout; eventual reconciliation.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account