InterviewDB
Experience
Cost Estimation OOD: Extensible Pricing Engine for Variable Services
phone
Interview Experience
Problem
Design a cost estimation engine for a platform that offers multiple services (e.g., compute, storage, network). Each service has its own pricing rules. The engine must support adding new service types without modifying existing code.
python
from abc import ABC, abstractmethod
class ServicePricer(ABC):
@abstractmethod
def estimate(self, usage: dict) -> float:
pass
class ComputePricer(ServicePricer):
# $0.05/hour per vCPU, $0.01/GB-hour RAM
def estimate(self, usage: dict) -> float:
# usage: {"vcpus": int, "ram_gb": float, "hours": float}
pass
class StoragePricer(ServicePricer):
# $0.023/GB-month
def estimate(self, usage: dict) -> float:
pass
class CostEstimator:
def add_service(self, name: str, pricer: ServicePricer) -> None: ...
def total_cost(self, usages: dict[str, dict]) -> float: ...
ce = CostEstimator()
ce.add_service("compute", ComputePricer())
ce.add_service("storage", StoragePricer())
ce.total_cost({"compute": {"vcpus":4,"ram_gb":16,"hours":720},
"storage": {"gb":100}})
-> (4*0.05 + 16*0.01)*720 + 100*0.023 = ...
Follow-ups
- Which design pattern does this use, and why is it appropriate here?
- How would you add tiered pricing (first 100 GB at rate A, next at rate B) cleanly?
- How do you handle currency conversion if services are priced in different currencies?
- How would you add a discount system without modifying the
ServicePricerinterface?
Full Details
Problem
Design a cost estimation engine for a platform that offers multiple services (e.g., compute, storage, network). Each service has its own pricing rules. The engine must support adding new service types without modifying existing code.
python
from abc import ABC, abstractmethod
class ServicePricer(ABC):
@abstractmethod
def estimate(self, usage: dict) -> float:
pass
class ComputePricer(ServicePricer):
# $0.05/hour per vCPU, $0.01/GB-hour RAM
def estimate(self, usage: dict) -> float:
# usage: {"vcpus": int, "ram_gb": float, "hours": float}
pass
class StoragePricer(ServicePricer):
# $0.023/GB-month
def estimate(self, usage: dict) -> float:
pass
class CostEstimator:
def add_service(self, name: str, pricer: ServicePricer) -> None: ...
def total_cost(self, usages: dict[str, dict]) -> float: ...
ce = CostEstimator()
ce.add_service("compute", ComputePricer())
ce.add_service("storage", StoragePricer())
ce.total_cost({"compute": {"vcpus":4,"ram_gb":16,"hours":720},
"storage": {"gb":100}})
-> (4*0.05 + 16*0.01)*720 + 100*0.023 = ...
Follow-ups
- Which design pattern does this use, and why is it appropriate here?
- How would you add tiered pricing (first 100 GB at rate A, next at rate B) cleanly?
- How do you handle currency conversion if services are priced in different currencies?
- How would you add a discount system without modifying the
ServicePricerinterface?
Free preview. Unlock all Zoox questions →
About This Question
This is a candidate experience report from a zoox interview during the phone round.
More Zoox Interview Questions
1p3a
zoox 3d simulation hiring manager video interview experience
InterviewDB
Formula Numbers: Evaluate Arithmetic Expressions with Named Variables
InterviewDB
Lane Control OOD: Multi-Lane Traffic Management System
1p3a
zoox data engineer sql technical interview insights
InterviewDB
Zoox SWE Onsite - H-index (Sorting/Math)