Skip to main content
πŸ”’ Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial β†’
⚑
← Coursesβ€ΊSystem Design for Python JuniorsModule 2 Β· Scalability + caching Β· Recapβ€ΊπŸŽ― Review: System design module 2 recapscenario43 / 105
+80 XP
Task
Build a small `cache_decision(hit_ratio, origin_cost_ms, cache_cost_ms)` that returns either `"cache"` or `"origin"`: - Expected latency for "cache" = `hit_ratio * cache_cost_ms + (1 - hit_ratio) * (cache_cost_ms + origin_cost_ms)` - Expected latency for "origin" = `origin_cost_ms` - Pick whichever is lower; break ties in favour of `"origin"` (simpler architecture wins on tie). Inputs: - `hit_ratio` is a float 0.0 to 1.0 - costs are positive ints (ms)
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
πŸ“Š Result
Press Run to see result...

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…