Price Cloud Billing Line Items With Swappable Discount Strategies

Last updated: November 29, 2026

Quick Overview

Model an invoice for cloud usage where each line item can carry a different discount rule (none, tiered sustained-use, committed-use percentage), and new discount types can be added without touching invoice code.

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

0

0

0 solved


Model an invoice for cloud usage where each line item can carry a different discount rule (none, tiered sustained-use, committed-use percentage), and new discount types can be added without touching invoice code.

Google Cloud billing combines many discount programs, which makes this a realistic onsite OOD exercise. The interviewer checks use of the strategy pattern, correct tiered arithmetic, money handled in integer cents with explicit rounding, and testability.

What the Interviewer Expects
  • Defines a discount interface and implements each rule as a strategy
  • Keeps LineItem and Invoice closed to modification when a new discount appears
  • Computes tiered pricing correctly across boundaries
  • Is explicit about rounding and integer cents
  • Writes unit tests at tier boundaries
Key Topics to Cover
strategy pattern
open-closed principle
tiered pricing
money rounding
unit testing
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 model stacking of two discounts and the order they apply?
  • Where should rounding happen: per line, per invoice, or per day?
  • How would you version pricing rules so old invoices can be recomputed exactly?
  • How do credits and free tiers fit this model?
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
  • LineItem(sku, units, unit_price_cents, discount) and Invoice.total_cents().
  • Discounts: none; sustained use with hour-based tiers over a 730-hour month; committed use with a flat percentage.
  • ...
High-Level Design

Discount.apply(units, base_cents) returns the discounted cents. LineItem multiplies units by price and delegates to its strategy; Invoice sums line items. Sustained use splits the month into qua...


Submit Your Answer
Markdown supported