Design an Extensible Fare Calculator With Pluggable Pricing Rules

Last updated: November 29, 2026

Quick Overview

Design the classes for a fare calculator where each city combines rules such as base fare, per-kilometer, per-minute, surge, minimum fare, and tolls, produces an itemized breakdown, and can add new rules without changing existing code.

Uber
Software Engineering Fundamentals
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Design the classes for a fare calculator where each city combines rules such as base fare, per-kilometer, per-minute, surge, minimum fare, and tolls, produces an itemized breakdown, and can add new rules without changing existing code.

Uber prices trips differently across hundreds of cities, so low-level design interviews often use fares to test abstraction choices. The interviewer looks for a rule interface, explicit ordering where rules interact, integer money, and a configuration path for new cities.

What the Interviewer Expects
  • Define a common rule interface (strategy pattern) and compose rules
  • Produce an itemized breakdown, not just a total
  • Make rule order explicit where rules interact (surge, minimum, tolls)
  • Use integer minor units for money
  • Build per-city calculators from configuration
Key Topics to Cover
Strategy pattern
Open-closed principle
Composition
Money handling
Configuration
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you add an airport surcharge that applies only to pickups in a geofence?
  • How do you guarantee the upfront price shown before the trip matches the charged price?
  • Where would promotions and discounts fit, before or after the minimum fare?
  • How would you unit test a city's whole fare policy?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Inputs: distance, duration, surge multiplier, tolls. Output: ordered list of labeled line items in cents and a total. Policies differ by city; some rules depend on what came before (surge multiplies t...

High-Level Design
  • TripFacts: immutable inputs.
  • FareBreakdown: accumulates line items and exposes a running subtotal.
  • FareRule: one method apply(trip, fare). Each concrete rule adds zero or more lines.
  • `...

Submit Your Answer
Markdown supported