Latest / CyberSecurity Summary / Machine Learning Systems: Designs that scale
Transcript
- 0:00Speaker 1: So imagine for a moment that you're nurturing this rare
- 0:05Speaker 1: exotic plant.
- 0:06Speaker 2: Okay. I'm picturing it.
- 0:07Speaker 1: You've got it in this perfectly climate-controlled greenhouse, right? Like
- 0:12Speaker 1: you control the soil pH, you measure the water down
- 0:14Speaker 1: to the exact milliliter, and the temperature is just always
- 0:18Speaker 1: hovering at exactly 72 degrees.
- 0:20Speaker 2: And naturally it thrives in there. Right. It thrives.
- 0:22Speaker 1: But then, you know, you take that delicate little plant,
- 0:25Speaker 1: you carry it outside, and you just toss it directly
- 0:27Speaker 1: into a Category 5 hurricane. Right.
- 0:29Speaker 2: I mean- it is going to get absolutely shredded.
- 0:32Speaker 1: Completely shredded because a greenhouse has, you know, static conditions
- 0:35Speaker 1: and a single caretaker. The real world has unpredictable wind shear,
- 0:40Speaker 1: flying debris, and just total chaos.
- 0:42Speaker 2: Right, yeah.
- 0:43Speaker 1: And that immediate catastrophic destruction is exactly what it feels
- 0:47Speaker 1: like when you take a pristine, mathematically beautiful machine learning
- 0:50Speaker 1: model one you built in a vacuum on a laptop
- 0:53Speaker 1: and you blindly deploy it out into the wild.
- 0:56Speaker 2: Out into the reality of, you know, Millions of concurrent users.
- 0:59Speaker 2: You've got dropping network connections, data corruption, endless edge cases.
- 1:03Speaker 2: It's a mess. It really is. I mean, the math
- 1:05Speaker 2: itself doesn't break. But the plumbing surrounding the math absolutely shatters.
- 1:09Speaker 1: Which brings us to today's deep dive. We are looking
- 1:12Speaker 1: at Jeff Smith's incredible book, Machine Learning Systems Designs That Scale.
- 1:17Speaker 1: And we are exploring why mathematically perfect models just constantly
- 1:22Speaker 1: fail in the real world. Right. Our mission for you
- 1:25Speaker 1: today is to really bridge that massive gap between theoretical
- 1:29Speaker 1: data science and real-world deployment. We're going to explore how
- 1:33Speaker 1: to stop fighting server fires, basically.
- 1:35Speaker 2: Yeah, and how to start building predictive systems that can
- 1:38Speaker 2: actually survive contact with live traffic. Exactly. And what really
- 1:43Speaker 2: sets the stage for this is the foreword of the
- 1:45Speaker 2: book by Sean Owen. He highlights this fundamental historical shift
- 1:48Speaker 2: in how we actually build these systems.
- 1:50Speaker 1: Oh, right, the shift from the old tools.
- 1:52Speaker 2: Yeah, if you look back, We used to rely on
- 1:53Speaker 2: these incredibly clunky JVM-based Hadoop tools to do the heavy
- 1:57Speaker 2: data lifting.
- 1:58Speaker 1: And Hadoop relied on MapReduce.
- 2:00Speaker 2: Exactly. Which fundamentally meant writing intermediate steps back to physical
- 2:04Speaker 2: hard disks. I mean, it was agonizingly slow.
- 2:07Speaker 1: It's writing to disk over and over. Yeah.
- 2:09Speaker 2: But recently, we transitioned to modern functional programming paradigms. Tools
- 2:15Speaker 2: like Spark, which handled data and memory, and just completely
- 2:18Speaker 2: changed our assumptions about scale and speed.
- 2:20Speaker 1: So we're going to dive into a completely different architectural
- 2:23Speaker 1: mindset today called reactive design, right? Just to take advantage
- 2:26Speaker 1: of these new tools. But before we learn how to
- 2:29Speaker 1: build a scalable system, I think we have to look
- 2:31Speaker 1: at a relatable, spectacular failure to understand the mechanics of
- 2:35Speaker 1: what actually goes wrong.
- 2:36Speaker 2: Oh, absolutely. Let me introduce you to a fictional startup
- 2:39Speaker 2: from our source material called Sniffable.
- 2:42Speaker 1: Sniffable?
- 2:43Speaker 2: Yeah, Sniffable. The business model is simple. It is Facebook.
- 2:47Speaker 2: But for dogs.
- 2:48Speaker 1: I mean, that's a... Completely untapped goldmine.
- 2:51Speaker 2: Naturally. So business is booming, but the product team wants
- 2:55Speaker 2: a new feature. They realize their most highly engaged users
- 2:59Speaker 2: are den mothers.
- 3:00Speaker 1: Denom mothers.
- 3:01Speaker 2: Yeah, like the canine equivalent of intense stage moms who
- 3:04Speaker 2: just desperately want their pets to be famous.
- 3:07Speaker 1: Oh, wow. Okay, I know the type.
- 3:09Speaker 2: Right. So Snivable decides to build the Pooch Predictor. It's
- 3:13Speaker 2: a tool where a den mother can draft a post,
- 3:15Speaker 2: they call it a bupdate, and before she hits send,
- 3:18Speaker 2: the system... analyzes her hashtags and predicts exactly how many
- 3:22Speaker 2: likes it will get.
- 3:23Speaker 1: Okay, let's unpack this. They have a very clear business
- 3:26Speaker 1: use case here. So they hand this off to their
- 3:28Speaker 1: lone data scientist, right? Yes.
- 3:31Speaker 2: And he does what a lot of folks would do
- 3:32Speaker 2: in a totally isolated environment.
- 3:34Speaker 1: Right. He writes a script. He pulls the raw interaction
- 3:38Speaker 1: data from their database into like a few flat CSV files.
- 3:43Speaker 1: And he runs a model learning algorithm over those files.
- 3:45Speaker 2: Classic approach.
- 3:46Speaker 1: Yeah. Yeah. He creates a predictive model, declares victory, and
- 3:50Speaker 1: then hands the finalized model over to a junior backend engineer.
- 3:53Speaker 2: And the junior engineer, who, you know, isn't a data scientist,
- 3:57Speaker 2: just embeds that finalized model directly into the main application's code.
- 4:01Speaker 2: And they ship it to production.
- 4:03Speaker 1: Which just triggers an immediate chain reaction of disasters. I mean,
- 4:06Speaker 1: first there was the stale data problem.
- 4:08Speaker 2: But yeah, the predictions basically never changed over time.
- 4:11Speaker 1: Right. The data scientists just assumed the model was constantly
- 4:14Speaker 1: updating itself. But because it was hard-coded into the app,
- 4:18Speaker 1: nobody realized it needed an automated pipeline to retrain it
- 4:21Speaker 1: daily with new data.
- 4:22Speaker 2: And then came the international incident.
- 4:26Speaker 1: Oh, this was bad.
- 4:27Speaker 2: Suddenly, for users outside the United States, Pooch Predictor started
- 4:32Speaker 2: predicting negative likes on their pup dates.
- 4:34Speaker 1: Which absolutely enraged the community. I mean, people felt the
- 4:37Speaker 1: app was actively insulting the adorableness of their dogs.
- 4:40Speaker 2: Yeah, it was this brutal bug in how they processed
- 4:43Speaker 2: location-based features that But it really highlights the danger of
- 4:46Speaker 2: untested edge cases. Definitely. But the final nail in the
- 4:49Speaker 2: coffin was the total system crash. Because to improve the model,
- 4:54Speaker 2: the data scientists required the app to send massive amounts
- 4:57Speaker 2: of telemetry data back to the database every single time
- 5:00Speaker 2: someone posted.
- 5:00Speaker 1: Wait, so they took a heavy telemetry requirement and just
- 5:03Speaker 1: shoved it into the main app thread. What did that
- 5:05Speaker 1: actually do to the servers mechanically?
- 5:07Speaker 2: It locked them up completely. I mean, every time a
- 5:10Speaker 2: user hit post, the main thread of the mobile app
- 5:12Speaker 2: had to pause and and wait for a heavy, synchronous
- 5:15Speaker 2: database write to finish before the user interface could update.
- 5:19Speaker 1: Oh, no.
- 5:20Speaker 2: Yeah. So when 10,000 denmothers posted it once, Sniffable literally
- 5:26Speaker 2: ran out of database connections. The threads backed up, the
- 5:29Speaker 2: servers threw out of memory exceptions, and the apps slowed
- 5:32Speaker 2: to an absolute crawl before just dropping pupdates entirely.
- 5:37Speaker 1: So they basically built this brilliant custom Ferrari engine, which
- 5:40Speaker 1: is the Algorithm, And they duct taped it to a
- 5:43Speaker 1: golf cart chassis.
- 5:44Speaker 2: Yeah, exactly.
- 5:45Speaker 1: The second they hit the gas, the torque just ripped
- 5:48Speaker 1: the chassis apart. Right.
- 5:49Speaker 2: And what's fascinating here is the underlying mindset issue. The
- 5:53Speaker 2: team viewed machine learning merely as a technique.
- 5:55Speaker 1: Right, like a math problem.
- 5:56Speaker 2: Exactly. To them, it was just an isolated math problem
- 5:59Speaker 2: to solve on a laptop. They fundamentally failed to view
- 6:03Speaker 2: it as an application. A real machine learning system has
- 6:06Speaker 2: five distinct phases, and you really cannot skip any of them.
- 6:09Speaker 1: Walk us through those phases really quick. Sure.
- 6:11Speaker 2: First is data collection, getting the data from the real
- 6:14Speaker 2: world safely without crashing your database. Second is feature and
- 6:19Speaker 2: concept generation, which is translating that raw data into a
- 6:23Speaker 2: format the model actually understands. Third is model learning, which,
- 6:27Speaker 2: by the way, is the only phase Sniffable actually focused on.
- 6:30Speaker 1: Of course.
- 6:31Speaker 2: Fourth is model publishing, moving the model out of the
- 6:34Speaker 2: lab and wrapping it in an API or a container.
- 6:37Speaker 2: And finally, responding, actually serving that prediction safely, to a
- 6:41Speaker 2: live user at scale.
- 6:43Speaker 1: So Sniffable completely ignored four out of the five phases?
- 6:46Speaker 2: Completely.
- 6:47Speaker 1: Wow. So if tight coupling and shared databases are what
- 6:50Speaker 1: brought Sniffable to its knees, I guess decoupling those pieces
- 6:54Speaker 1: is the only way forward, which brings us to the
- 6:56Speaker 1: reactive approach. Right.
- 6:57Speaker 2: The reactive approach is a fundamentally different architectural mindset, and
- 7:00Speaker 2: it's built on four core traits.
- 7:01Speaker 1: Okay.
- 7:02Speaker 2: First, a system must be responsive. It has to consistently
- 7:06Speaker 2: return timely responses no matter what. Second, it must be resilient.
- 7:11Speaker 2: It has to maintain that responsiveness even when hardware fails
- 7:14Speaker 2: or networks drop. Third, it needs to be elastic, so
- 7:19Speaker 2: effortlessly scaling up when traffic spikes and scaling down to
- 7:22Speaker 2: save money when things are quiet.
- 7:24Speaker 1: It makes sense.
- 7:25Speaker 2: And fourth, it must be message-driven. This means components communicate
- 7:29Speaker 2: via asynchronous, non-blocking message passing. It ensures loose coupling.
- 7:34Speaker 1: Okay, I am going to challenge you on this because responsive, resilient...
- 7:39Speaker 1: I mean, those sound like empty buzzwords to me.
- 7:42Speaker 2: Fair enough.
- 7:42Speaker 1: Every company claims their software is resilient. So how do
- 7:45Speaker 1: you physically force a system to behave this way at
- 7:48Speaker 1: a code level?
- 7:49Speaker 2: It is a vital question. You do not just wish
- 7:52Speaker 2: these traits into existence. You engineer them using three highly
- 7:55Speaker 2: specific strategies.
- 7:56Speaker 1: Okay, what's the first one?
- 7:57Speaker 2: First is replication. You redundantly process data. So let's look
- 8:00Speaker 2: at Spark, which we mentioned earlier. Spark uses something called
- 8:03Speaker 2: a directed acyclic graph or a DAG.
- 8:05Speaker 1: A BAG-GAG. Right.
- 8:06Speaker 2: It doesn't just pass raw data around. It keeps a
- 8:08Speaker 2: meticulous step-by-step log of the transformations required to process the data.
- 8:13Speaker 1: So wait, if a server node physically catches fire in
- 8:17Speaker 1: the middle of training a model?
- 8:19Speaker 2: The system doesn't panic. The master node simply looks at
- 8:22Speaker 2: the DAG, assigns a new healthy node, and that new
- 8:26Speaker 2: node grabs the original data slice and replays the exact steps.
- 8:31Speaker 1: Oh, wow.
- 8:31Speaker 2: Yeah, it doesn't even need to ask the dead node
- 8:34Speaker 2: where it left off. That provides absolute resilience without a
- 8:37Speaker 2: single point of failure.
- 8:38Speaker 1: Okay, that covers infrastructure failure. But what about logic failures?
- 8:42Speaker 1: Like in the sniffable disaster, a bad hashtag threw an
- 8:46Speaker 1: exception in the model and it took down the entire
- 8:48Speaker 1: mobile app.
- 8:49Speaker 2: That requires a second strategy, which is containment. You have
- 8:52Speaker 2: to isolate failures so they cannot cascade across the network.
- 8:55Speaker 1: Oh, I see it. Like watertight doors on a submarine.
- 8:58Speaker 2: Yes.
- 8:59Speaker 1: Like if one compartment breaches and floods, you just seal
- 9:01Speaker 1: the bulkhead door. I mean, you might lose the use
- 9:04Speaker 1: of that specific room, but the submarine itself doesn't sink.
- 9:08Speaker 2: That is the perfect analogy. If the machine learning model
- 9:10Speaker 2: throws a null pointer exception, that error must be trapped
- 9:14Speaker 2: inside its own isolated container. The user might not get
- 9:17Speaker 2: their pooch predictor estimate. But the main app doesn't crash.
- 9:21Speaker 2: They can still post their photo.
- 9:23Speaker 1: So if we connect this to the bigger picture, containing
- 9:26Speaker 1: an error is great, but we still have a broken
- 9:28Speaker 1: model sitting in a flooded compartment, basically. How does the
- 9:32Speaker 1: system actually fix itself?
- 9:34Speaker 2: This leads to the third strategy, supervision. You build an
- 9:37Speaker 2: architectural component called a model supervisor.
- 9:40Speaker 1: But how does a supervisor sit outside the application to
- 9:43Speaker 1: watch it without, you know, getting dragged down if the
- 9:46Speaker 1: app crashes?
- 9:47Speaker 2: It utilizes an actor model. So the supervisor is an
- 9:50Speaker 2: entirely separate, isolated process.
- 9:52Speaker 1: Okay.
- 9:53Speaker 2: It isn't running the model. It's simply pinging the model's
- 9:56Speaker 2: container and watching the health metrics.
- 9:58Speaker 1: Oh, so it's just checking in.
- 10:00Speaker 2: Exactly. If the model starts acting up, say it starts
- 10:02Speaker 2: spitting out those negative likes, the supervisor intercepts the traffic.
- 10:06Speaker 2: And because it sits outside the blast radius, it can
- 10:08Speaker 2: literally issue a kill command to destroy the rogue model's
- 10:12Speaker 2: container and seamlessly spin up a fresh backup version.
- 10:15Speaker 1: That's wild. It makes the system completely self-healing.
- 10:18Speaker 2: It really does.
- 10:19Speaker 1: Here's where it gets really interesting, though. Standard software deals
- 10:22Speaker 1: with finite transactions, right? Like a bank transfer has a beginning,
- 10:26Speaker 1: a middle, and an end. True. But our sources point
- 10:28Speaker 1: out that machine learning systems have this terrifying quirk that
- 10:31Speaker 1: threatens to break all of this reactive design. The data
- 10:34Speaker 1: you are dealing with is effectively infinite.
- 10:37Speaker 2: Yes. Think about the problem of scale with a social
- 10:40Speaker 2: network like Sniffable. You cannot possibly know, categorize, or store data.
- 10:46Speaker 2: Every single variation of a future pup date. Right. You
- 10:49Speaker 2: have infinite variations in dog breeds, lighting, filters, typos. I mean,
- 10:53Speaker 2: is a user typing hashtag adorable with you or hashtag
- 10:57Speaker 2: adorable with any? The stream of inputs from the real
- 11:00Speaker 2: world has no start and no end.
- 11:02Speaker 1: Let me stop you there. My hard drive is a
- 11:04Speaker 1: finite piece of metal. RAM is finite. How does a
- 11:07Speaker 1: physical computer hold an infinite stream of data and memory
- 11:09Speaker 1: without immediately crashing?
- 11:11Speaker 2: It sounds paradoxical, I know, but functional programming solves this
- 11:15Speaker 2: using a concept called laziness.
- 11:16Speaker 1: Laziness, which is usually a terrible trait in an engineer.
- 11:20Speaker 2: Right, but a brilliant one in a compiler. In functional programming,
- 11:24Speaker 2: laziness means a delay of execution. Okay. So instead of
- 11:27Speaker 2: trying to load a million rows of data into RAM
- 11:29Speaker 2: at once, which is impossible if the data never ends,
- 11:33Speaker 2: the system creates a pointer to an unevaluated expression. We
- 11:37Speaker 2: call it a thunk.
- 11:38Speaker 1: A thunk. So it's not actually holding the data. It's
- 11:40Speaker 1: holding like an IOU.
- 11:41Speaker 2: Precisely. The program basically says, I know the mathematical formula
- 11:45Speaker 2: to calculate this data whenever you actually need it. Right.
- 11:48Speaker 2: It conceives the data as an infinite flowing stream, but
- 11:51Speaker 2: it only evaluates the expression and pulls the data into
- 11:54Speaker 2: memory at the exact fraction of a second that the
- 11:56Speaker 2: final output is demanded by the user.
- 11:59Speaker 1: Wow.
- 11:59Speaker 2: Yeah. It does absolutely no work until it is forced to.
- 12:02Speaker 1: It just sips from the fire hose on demand. But
- 12:05Speaker 1: doing that safely seems incredible. incredibly fragile.
- 12:08Speaker 2: It is, which is why laziness only works if you
- 12:10Speaker 2: strictly enforce something called pure functions. This is a core
- 12:14Speaker 2: tenet of languages like Scala, which Jeff Smith relies heavily
- 12:17Speaker 2: on in the text.
- 12:18Speaker 1: So what exactly makes a function pure?
- 12:20Speaker 2: A pure function has two unbreakable rules. First, it always
- 12:26Speaker 2: returns the exact same output for the exact same input,
- 12:29Speaker 2: which is called referential transparency. Second, It has zero side effects. Okay.
- 12:34Speaker 1: Explain what a side effect is in this context, because
- 12:36Speaker 1: getting rid of them is a massive takeaway for anyone
- 12:39Speaker 1: writing code.
- 12:40Speaker 2: Sure. A side effect is when a function modifies a variable,
- 12:44Speaker 2: updates a database, or changes a state outside of its
- 12:47Speaker 2: own local scope. When you evaluate a lazy function hours
- 12:51Speaker 2: after you wrote the IOU, if evaluating it suddenly changes
- 12:54Speaker 2: a global variable that another part of your app relies on,
- 12:57Speaker 2: your system will just collapse in unpredictable ways.
- 13:00Speaker 1: Ah, it's the sneaky state change bug. So a pure
- 13:03Speaker 1: function just takes an input, returns an output, and touches
- 13:06Speaker 1: absolutely nothing else in the world.
- 13:08Speaker 2: Exactly. But even if you master pure functions and lazy streams,
- 13:12Speaker 2: you still have to face the ultimate boss of machine learning,
- 13:15Speaker 2: which is the real world.
- 13:16Speaker 1: Right. The data coming in isn't just infinite. It is messy,
- 13:19Speaker 1: it's delayed, and wildly uncertain.
- 13:21Speaker 2: Very much so.
- 13:22Speaker 1: Let's talk about that uncertainty. Say a front-end developer at
- 13:25Speaker 1: Sniffable decides to change how timestamps are formatted on the
- 13:29Speaker 1: mobile app.
- 13:29Speaker 2: Oh boy.
- 13:30Speaker 1: They silently move from a standard Unix integer to an
- 13:33Speaker 1: ISO string, and they just don't tell the data team.
- 13:36Speaker 2: A classic breakdown in communication. And if your database simply
- 13:40Speaker 2: accepts that new string and overwrites the old format, your
- 13:43Speaker 2: downstream machine learning model, which is mathematically expecting an integer,
- 13:47Speaker 2: will suddenly panic and crash.
- 13:49Speaker 1: So how does a reactive system handle the reality of
- 13:53Speaker 1: bad or changing data?
- 13:55Speaker 2: You have to rethink storage completely. In a reactive system,
- 13:58Speaker 2: you do not overwrite data. Ever. You record immutable facts.
- 14:02Speaker 1: Immutable facts. Yes.
- 14:04Speaker 2: When a payload of data comes in from the real world,
- 14:06Speaker 2: no matter how messy or weird it is, you save
- 14:08Speaker 2: the raw, exact payload. You write that complex truth in stone,
- 14:12Speaker 2: you append it to a log, and you never, ever
- 14:15Speaker 2: modify it.
- 14:15Speaker 1: So you're just capturing history exactly as it happened.
- 14:18Speaker 2: Right. and you let the machine learning model figure out
- 14:20Speaker 2: how to parse that history later. This leads to a
- 14:23Speaker 2: fascinating prediction strategy called possible worlds.
- 14:25Speaker 1: That sounds incredibly theoretical.
- 14:27Speaker 2: I know, but it's actually highly practical. In machine learning,
- 14:31Speaker 2: you rarely have one definitive truth about the future.
- 14:34Speaker 1: Okay.
- 14:34Speaker 2: Say Sniffable wants to allocate server capacity for the next hour,
- 14:37Speaker 2: and they need to know how many likes French Bulldogs
- 14:39Speaker 2: are going to get. You don't calculate one rigid number.
- 14:42Speaker 2: You calculate multiple realities.
- 14:44Speaker 1: Walk me through the math on that.
- 14:46Speaker 2: Okay, so... World A is the historical baseline. Based on
- 14:50Speaker 2: past behavior, we expect 6,500 pup dates.
- 14:52Speaker 1: Right.
- 14:53Speaker 2: We multiply that by our historical average of 23 likes
- 14:56Speaker 2: per post. That gives us an expectation of 149,500 likes.
- 15:01Speaker 1: Straightforward enough.
- 15:02Speaker 2: But World B is the ML-predicted reality. Our model is
- 15:05Speaker 2: analyzing real-time trending hashtags and projects, a massive surge, let's
- 15:11Speaker 2: say 7,250 pup dates. Wow. Okay. And because Frenchies are
- 15:14Speaker 2: currently viral... It predicts 28 likes each. That gives us 203,300 likes.
- 15:19Speaker 1: So two very different numbers.
- 15:21Speaker 2: Exactly. By querying across these different possible worlds simultaneously, the
- 15:25Speaker 2: system understands the range of uncertainty and spins up enough
- 15:28Speaker 2: server capacity to handle the absolute worst-case scenario.
- 15:31Speaker 1: That's brilliant. I want to raise the stakes here with
- 15:34Speaker 1: an example from the book that perfectly illustrates the danger
- 15:36Speaker 1: of scale. Forget standard social media posting. Let's talk about
- 15:40Speaker 1: Hollywood Star.
- 15:41Speaker 2: Oh, right. Their reality singing competition for dogs.
- 15:44Speaker 1: Yes. Dogs barking to music on live television being judged.
- 15:49Speaker 1: And millions of viewers at home are voting on the
- 15:52Speaker 1: sniffable app at the exact same millisecond. I mean, the
- 15:55Speaker 1: traffic spikes are instantaneous and massive.
- 15:58Speaker 2: This introduces a terrifying concept in distributed systems called tail latency.
- 16:03Speaker 1: Tail latency. Yeah.
- 16:05Speaker 2: When millions of users are voting... A single vote doesn't
- 16:08Speaker 2: just hit one server. It might touch dozens of microservices.
- 16:11Speaker 1: Like authentication, fraud detection, the vote tally database.
- 16:15Speaker 2: Exactly.
- 16:16Speaker 1: And the wait time for the user isn't the average
- 16:18Speaker 1: speed of those services combined.
- 16:20Speaker 2: No. The total wait time is entirely dictated by the
- 16:23Speaker 2: single slowest request in the chain. That is the tail latency. Well, man.
- 16:28Speaker 2: If you have 99 microservices operating in one millisecond, but
- 16:32Speaker 2: one remote server handling fraud detection hangs for five seconds.
- 16:35Speaker 1: The user's mobile app freezes for five full seconds. Exactly.
- 16:38Speaker 1: This raises an important question, though. How do you physically
- 16:42Speaker 1: prevent one struggling backend server from completely freezing the user
- 16:46Speaker 1: interface for millions of people?
- 16:49Speaker 2: This is where functional programming languages like Scala really earn
- 16:52Speaker 2: their keep. Scala has built in primitives to handle this asynchronously. First,
- 16:58Speaker 2: it uses something called futures.
- 17:00Speaker 1: Futures. Right.
- 17:01Speaker 2: Instead of the main application thread stopping and waiting for
- 17:04Speaker 2: that fraud server to respond, which is called blocking IO,
- 17:07Speaker 2: it fires off a future.
- 17:09Speaker 1: So it essentially delegates the task. It says, you know,
- 17:11Speaker 1: go get this data on a background thread. Let me
- 17:13Speaker 1: know when you have it, but I'm going to keep
- 17:14Speaker 1: processing other things.
- 17:16Speaker 2: Exactly. The main thread stays completely snappy. But Scala pairs
- 17:20Speaker 2: futures with something even more powerful called option types.
- 17:24Speaker 1: OK, tell me about those.
- 17:25Speaker 2: When the app asks the database for the vote count
- 17:28Speaker 2: for a dog named NomNum, It does not just get
- 17:31Speaker 2: an integer back. It gets an option.
- 17:33Speaker 1: Explain how an option type mechanically differs from a regular variable.
- 17:38Speaker 1: Because this is the key to preventing crashes, right?
- 17:40Speaker 2: It is. An option type acts like a highly secure
- 17:43Speaker 2: locked box. That box can only contain one of two things.
- 17:48Speaker 2: It either contains some value, like the number 42, or
- 17:51Speaker 2: it contains none, meaning the data is missing or just
- 17:54Speaker 2: hasn't arrived yet. Okay. The magic here is that the
- 17:57Speaker 2: compiler will physically refuse to compile your code unless you
- 18:01Speaker 2: use pattern matching to explicitly write logic for both scenarios.
- 18:06Speaker 1: So it forces the programmer to handle the uncertainty up front.
- 18:10Speaker 1: It physically prevents a null pointer exception because you can
- 18:13Speaker 1: never accidentally call a variable that doesn't exist.
- 18:16Speaker 2: Exactly. You have to tell the system, what do we
- 18:19Speaker 2: display if the database says sum 42, and what do
- 18:22Speaker 2: we display if the database returns? None, because the network
- 18:26Speaker 2: is congested.
- 18:26Speaker 1: So what does this all mean for us? To me,
- 18:29Speaker 1: it means we have to actively design for failure. It's
- 18:31Speaker 1: like a world-class restaurant. If the kitchen runs out of
- 18:34Speaker 1: the signature dish, the head chef doesn't run to the
- 18:36Speaker 1: front door, lock it, shut off the power, and scream
- 18:38Speaker 1: in panic.
- 18:39Speaker 2: Which is the architectural equivalent of what Sniffable did, honestly.
- 18:42Speaker 1: Right. Instead, the waiter gracefully comes to your table, apologizes,
- 18:46Speaker 1: and offers you a complimentary appetizer.
- 18:48Speaker 2: It is called graceful degradation.
- 18:51Speaker 1: Exactly. In our Hollywood Star app, because we are using
- 18:54Speaker 1: futures and option types, we can program a strict timeout.
- 18:58Speaker 1: We can say, if that remote database takes longer than
- 19:01Speaker 1: 500 milliseconds to fetch the live vote count, abandon the request.
- 19:05Speaker 2: Just abandon it.
- 19:06Speaker 1: Yeah. Just return none and use pattern matching to display
- 19:10Speaker 1: the historical average to the user's screen instead.
- 19:12Speaker 2: And is displaying the historical average perfectly mathematically accurate in
- 19:16Speaker 2: that exact millisecond?
- 19:18Speaker 1: No.
- 19:19Speaker 2: But the app stays incredibly fast, the main thread doesn't
- 19:23Speaker 2: lock up, and the user remains completely engaged.
- 19:26Speaker 1: Because the eventual consistency of the database catches up a
- 19:29Speaker 1: second later anyway.
- 19:30Speaker 2: Precisely.
- 19:31Speaker 1: It is a brilliant shift in perspective. So let's look
- 19:34Speaker 1: at the journey we've taken today. We moved away from
- 19:36Speaker 1: the naive, firefighting, duct-taped architecture of the original Pooch predictor.
- 19:41Speaker 2: We really did.
- 19:42Speaker 1: We explored how to build a robust, reactive machine learning system.
- 19:45Speaker 1: We learned how to use pure functions and lazy evaluation
- 19:48Speaker 1: to handle infinite difficulties. data streams without running out of memory.
- 19:52Speaker 1: We learned how to store immutable facts to honestly capture
- 19:55Speaker 1: reality and how to use futures and option types to
- 19:58Speaker 1: force that graceful degradation.
- 20:00Speaker 2: And if there is one overarching takeaway for you today,
- 20:03Speaker 2: whether you are building, managing or even just interacting with
- 20:06Speaker 2: these massive machine learning systems. It is realizing that machine
- 20:10Speaker 2: learning is an application.
- 20:12Speaker 1: It really is.
- 20:13Speaker 2: It is an entire ecosystem of data pipelines, containment strategies,
- 20:17Speaker 2: and supervisors. It is not just an isolated algorithm. And
- 20:21Speaker 2: when you treat it like a holistic application, that is
- 20:25Speaker 2: your shortcut. to creating software that actually survives contact with
- 20:29Speaker 2: the real world.
- 20:30Speaker 1: Which leaves us with a final, slightly provocative thought for
- 20:32Speaker 1: you to mull over. We have spent this entire deep
- 20:35Speaker 1: dive establishing that the most resilient machine learning systems are
- 20:39Speaker 1: fundamentally built on accepting uncertainty. Right. They are explicitly designed
- 20:43Speaker 1: to handle maybe, you know, to process multiple possible worlds
- 20:47Speaker 1: and to degrade gracefully when they don't know the exact truth.
- 20:50Speaker 1: But think about the world these models are being deployed into.
- 20:54Speaker 1: Our legal systems, our compliance frameworks, and our regulatory laws
- 20:58Speaker 1: demand absolute black and white deterministic certainty.
- 21:02Speaker 2: They absolutely do.
- 21:03Speaker 1: So it makes you wonder, when a reactive system is
- 21:06Speaker 1: perfectly comfortable with intentionally being a little bit wrong to survive,
- 21:11Speaker 1: how long will it take for our rigid legal structures
- 21:14Speaker 1: to catch up to the reality of how this software
- 21:16Speaker 1: actually works?
- 21:17Speaker 2: That's a great question.
- 21:18Speaker 1: Because it really is the only way that delicate plant
- 21:20Speaker 1: survives the hurricane. Thanks for taking a deep dive with us.