-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Object-Oriented Scala
-
Section 4: Functional Scala
-
Section 5: Collections in Depth
-
Section 6: Type System
-
Section 7: Concurrency and Ecosystem
-
Section 8: Practical Projects
-
Section 9: Interview Practice
-
Section 10: Data Structures and Algorithms in Scala
-
Section 11: More Practice Exercises
-
Section 12: Advanced Functional Patterns
-
Section 13: More Ecosystem
-
Section 14: Scala Collections Library Deep Dive
-
Section 15: Scala Standard Library Deep Dive
-
Section 16: Akka Ecosystem Deep Dive
-
Section 17: Cats and Cats Effect Deep Dive
-
Section 18: Play Framework Deep Dive
-
Section 19: Apache Spark with Scala Deep Dive
-
Section 20: Scala Build Tools Deep Dive
-
Section 21: Scala 3 Specific Features
-
90: Union and Intersection Types
-
Section 22: Scala Testing Deep Dive
-
Section 23: Functional Domain Modeling
-
Section 24: More Data Structures and Algorithms in Scala
-
Section 25: Scala for Data Engineering
-
Section 26: More Practical Projects
-
Section 27: More Interview and Review
-
Section 28: ZIO Ecosystem Deep Dive
-
Section 29: Scala for Machine Learning
-
Section 30: Scala Microservices Architecture
-
Section 31: Scala Type System Deep Dive
-
Section 32: More Practice and Drills
-
Section 33: Scala Performance Deep Dive
-
Section 34: Scala Ecosystem Tooling
-
Section 35: Scala for Reactive Systems
-
Section 36: More Real-World Case Studies
-
Section 37: Scala for Financial Systems
-
Section 38: Scala GraphQL and gRPC
-
Section 39: More Final Projects
-
Section 40: More Interview and Final Review
-
Section 41: Scala for Streaming Data
-
Section 42: Scala Security Practices
-
Section 43: More Language Deep Dive
-
Section 44: Scala Command-Line Tools
-
Section 45: Scala Documentation and Style
-
Section 46: Scala Dependency Management
-
Section 47: More Practical Backend Patterns
-
Section 48: Scala for Event-Driven Architecture
-
Section 49: More Practice Drills Round 2
-
Section 50: Scala Compiler Deep Dive
-
Section 51: Scala for Web Frontends
-
Section 52: More Data Engineering Practice
-
Section 53: Scala Observability
-
Section 54: More Advanced Practice Projects
-
Section 55: Scala for Legacy Java Integration
-
Section 56: More Testing Practice
-
Section 57: Final Mastery Review
-
Section 58: Scala History and Ecosystem Context
-
Section 59: More Concurrency Patterns
-
Section 60: Scala for Configuration Management
-
Section 61: More Domain Modeling Practice
117: Interview Practice: System Design Basics for Scala Backend Roles
When you hit the system design stage of a Scala interview, the interviewer isn't just checking if you know how to draw boxes and arrows. They're looking to see if you can apply the philosophy of the language—immutability, type safety, and non-blocking concurrency—to the architecture itself. I've seen a lot of great coders stumble here because they treat system design as a separate, generic exercise, forgetting that the tools we use in Scala (like ZIO, Cats Effect, or Pekko) actually dictate how we should approach scalability.
Let's take a concrete example: designing a Real-Time Price Alert System. The requirement is simple: users follow a product, and as soon as the price drops below their threshold, they get a push notification. It sounds trivial, but this is where the gap between a "junior" design and a "senior" design becomes obvious.
The Polling Trap and Database Exhaustion
The naive way to build this is the "Cron-and-Query" approach. You'd probably suggest a scheduled job that runs every minute, queries the database for all active alerts, compares the current price to the user's threshold, and sends a notification if the condition is met. On paper, it works. In a small demo, it's actually faster to implement.
But here's where it breaks. As your user base grows to millions of alerts, that "simple" query becomes a monster. You're hitting the database every 60 seconds for data that likely hasn't changed for 99% of your users. You're wasting CPU cycles, locking rows, and creating massive spikes in database load. If you try to scale this by adding more polling workers, you aren't solving the problem; you're just DOSing your own database more efficiently. In an interview, if you suggest polling for a high-scale system, it's a red flag that you're thinking in synchronous, imperative terms rather than reactive ones.
Event-Driven Reactivity with Scala Streams
The better way is to invert the flow. Instead of the alert system asking the database "Is it time yet?", we make the price-update service tell the alert system "The price just changed."
I'd propose an event-driven architecture using a message broker like Kafka. Whenever a price changes, a PriceChanged event is published to a topic. Your Scala backend then consumes this stream using something like FS2 or Pekko Streams. Because Scala handles non-blocking I/O so well, a single instance of your service can handle thousands of concurrent events without choking on thread overhead.
case class PriceChanged(productId: UUID, newPrice: BigDecimal) case class Alert(userId: UUID, productId: UUID, threshold: BigDecimal) // Imagine a stream processing logic like this: priceEventStream .mapAsync(10) { event => alertRepository.findAlertsForProduct(event.productId) .filter(_.threshold >= event.newPrice) } .flatMap(alerts => alerts.toStream) .evalMap(alert => notificationService.send(alert))Now, the system only does work when something actually happens. We've moved from a system that scales based on the number of users to one that scales based on the number of price changes. That is a massive architectural win.
The Trade-off: Consistency vs. Complexity
Now, if I'm your interviewer, I'm going to push back. I'll ask, "What happens if the Kafka consumer crashes? Do users miss their alerts?" This is where you show your maturity. You admit that the event-driven approach introduces eventual consistency. Unlike the polling method, where you have a guaranteed (albeit slow) check every minute, the event-driven system depends on the reliability of the message broker and the consumer's offset management.
I'd argue that for a price alert, eventual consistency is perfectly acceptable. A user getting a notification 2 seconds late is fine; a database crashing under the weight of a million SELECT statements is not. The "cost" here is the added operational complexity of managing Kafka and handling idempotent writes (ensuring you don't send the same alert twice if a consumer restarts), but the "gain" is a system that can scale linearly without killing your data layer.
📋 Practical Task
Exercise: Designing a Rate-Limited Notification Dispatcher
In our Price Alert System, we discovered that an event-driven approach is superior. However, there is a new problem: if a popular product's price fluctuates rapidly, we might accidentally send 50 notifications to a single user in one minute, which is a great way to get your app uninstalled.
Your Task: Write a system design proposal (in prose or a structured outline) for a "Notification Dispatcher" layer that sits between the Alert Logic and the actual Push Service. Your design must address the following:
- The Strategy: How will you track how many notifications a user has received in the last window of time? (Think about where this state lives—local memory, Redis, etc.).
- The Concurrency: How will you ensure that if two alerts for the same user hit the dispatcher at the exact same millisecond, you don't bypass the rate limit?
- The Scala Edge: Explain how you would use a specific Scala concurrency primitive (e.g., ZIO Ref, Akka Actor, or a specific FS2 operator) to handle this state safely.
Avoid a generic "I will use a database" answer. Focus on the trade-offs between latency and strictness.
There are no comments for now.