Skip to Content
Course content

238: Notable Companies and Systems Built with Scala

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Think of choosing a programming language for a massive system like choosing the foundation for a skyscraper. If you're building a two-story house, a simple concrete slab is fine—it's fast and cheap. But if you're building something that needs to support 100 floors and withstand hurricane-force winds, you need deep-bore pilings and reinforced steel. You accept the complexity of the construction process because the cost of a collapse is unthinkable.

Scala is that reinforced steel. It provides the "rigidity" of a strong static type system to prevent runtime collapses, but it keeps the "flexibility" of functional programming so your developers don't go insane while writing the code. When you look at the companies that use Scala, you'll notice a pattern: they aren't just building apps; they're building infrastructure that handles millions of concurrent events per second.

The Great Twitter Migration

You can't talk about Scala without talking about Twitter. In the early days, Twitter was built on Ruby on Rails. It was great for prototyping, but as they scaled, they hit the "Fail Whale"—that infamous screen telling you the site was over capacity. Ruby's Global Interpreter Lock (GIL) and memory overhead simply couldn't keep up with the firehose of tweets.

Twitter didn't just tweak their code; they migrated their core backend to Scala. Why? Because Scala runs on the JVM, giving them industrial-grade memory management, but more importantly, it gave them the Akka toolkit. Akka allows you to build "Actor-based" systems where every piece of the system is an independent entity that communicates via messages. If one actor crashes, it doesn't take down the whole skyscraper; the supervisor just restarts it. I've seen a lot of devs try to replicate this in other languages, but Scala's type system makes these asynchronous patterns actually maintainable.

The Backbone of Big Data: Apache Spark

If you've ever worked with a massive dataset—I'm talking petabytes of logs or financial transactions—you've likely used Apache Spark. Spark is written in Scala. This wasn't an accident. To process data across a cluster of a thousand machines, you need a language that can express complex transformations (like MapReduce) concisely but execute them with the efficiency of a compiled language.

Because Scala treats functions as first-class citizens, Spark can define a computation once and then ship that logic across a network to where the data actually lives. If this were written in a purely imperative language, the boilerplate would be staggering. If it were written in a purely interpreted language, it would be too slow to be viable.

Netflix and the Art of Resilience

Netflix uses Scala heavily for their edge services and their data pipelines. Specifically, they've leaned into Scala's ability to handle "asynchronous non-blocking I/O." When you hit the "Play" button, Netflix isn't just fetching a file; it's hitting dozens of microservices to check your subscription, your preferences, and the closest CDN server to your house.

Using Scala allows them to trigger all those requests simultaneously without locking up threads. I always tell my students that the "magic" here isn't just the language, but how Scala blends the Object-Oriented world (for organizing the business logic) with the Functional world (for handling the data flow). It’s the best of both worlds for a company that cannot afford a single second of downtime.

Why not just use Java?

You'll often hear people ask, "If it's on the JVM, why not just use Java?" Well, you can. But Java is verbose. To do in Java what Scala does in one line of a for-comprehension might take you ten lines of nested loops and null checks. When you're managing a system as complex as LinkedIn's (where Kafka was born), reducing the "surface area" of your code reduces the number of places bugs can hide. Scala lets you be more expressive without sacrificing the performance of the JVM.




📋 Practical Task

Build a Miniature Asynchronous Notification Dispatcher

To understand why companies like Twitter use Scala for high-volume systems, you're going to build a simplified version of a notification dispatcher. Instead of a full Akka setup, you'll use Scala's Future and ExecutionContext to simulate a system that handles multiple notification channels (Email, SMS, Push) without blocking the main thread.

Your Requirements:

  • Create a case class Notification(userId: String, message: String).
  • Implement a Dispatcher object with three methods: sendEmail, sendSMS, and sendPush. Each method must return a Future[Boolean] and use Thread.sleep (inside a Future block) to simulate network latency.
  • Write a main method that takes a list of Notification objects and dispatches them to all three channels simultaneously.
  • Use Future.sequence to wait for all notifications for a single user to complete before printing "Notification cycle complete for user X".
  • Ensure your code handles the case where one of the services "fails" (returns a failed Future) without crashing the entire dispatcher.

Goal: Demonstrate that you can trigger multiple high-latency external calls in parallel and aggregate their results without locking the execution thread.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.