Latest / CyberSecurity Summary / Clojure Applied: From Practice to Practitioner
Transcript
- 0:00Speaker 1: So if you are staring at a blank screen right now,
- 0:03Speaker 1: and you know the basic syntax of closure, you know
- 0:07Speaker 1: the parentheses, the vectors, the pure functions. It's fun stuff, yeah, exactly,
- 0:12Speaker 1: the fun stuff. But that screen does not look like
- 0:15Speaker 1: limitless potential right now. It looks like a terrifying void.
- 0:18Speaker 2: I mean, we've all been there.
- 0:19Speaker 1: You know the vocabulary, sure, but you are sitting there
- 0:22Speaker 1: wondering how to build a real, production ready system that
- 0:26Speaker 1: can actually survive contact with the real world. So welcome
- 0:31Speaker 1: to this deep dive.
- 0:32Speaker 2: Glad to be here.
- 0:32Speaker 1: Our mission today is to pull you out of the
- 0:35Speaker 1: toy box basically and drop you straight into the professional workplace.
- 0:39Speaker 1: We are extracting the core architectural insights from this highly
- 0:43Speaker 1: practical technical manual called Closure Applied from Practice to Practitioner.
- 0:47Speaker 2: Yeah, written by Ben Vangrift and Alex Miller, and it's
- 0:51Speaker 2: I mean, the transition from writing little scripts to architecting
- 0:54Speaker 2: enterprise systems. It requires a fundamental shift in how you
- 0:58Speaker 2: model reality, time and change.
- 1:00Speaker 1: Especially in a multi core world, right exactly.
- 1:03Speaker 2: So we are going to explore how to architect a
- 1:06Speaker 2: system starting from the microscopic level of your data models,
- 1:10Speaker 2: moving all the way up to the macroscopic level of
- 1:12Speaker 2: complex parallel processing components.
- 1:15Speaker 1: Okay, so to get to those massive concurrent systems, we
- 1:18Speaker 1: have to start the absolute foundation. We need to define
- 1:21Speaker 1: the very shape of the data flowing through the application.
- 1:24Speaker 2: Right, the atoms of the system.
- 1:25Speaker 1: Yeah, So if we want to represent a domain entity
- 1:29Speaker 1: and a functional system, the source highlights a major choice
- 1:32Speaker 1: developers have to make right out of the gate, and
- 1:34Speaker 1: that's choosing between maps and records.
- 1:36Speaker 2: Which is a huge decision because maps and records they
- 1:39Speaker 2: present the exact same basic interface enclosure. You ask for
- 1:42Speaker 2: an attribute value by providing a key, But under the hood,
- 1:46Speaker 2: I mean they serve very different architectural purposes.
- 1:48Speaker 1: Well, maps are the flexible ones, right right.
- 1:50Speaker 2: Maps have absolutely no pre defined structure. You can add
- 1:53Speaker 2: or remove anything at any time. That flexibility makes them
- 1:56Speaker 2: perfect for public facing APIs. Like when you ingest Jason
- 1:59Speaker 2: from a way request, you really don't want to constrain
- 2:01Speaker 2: your callers or build fragile parsing logic.
- 2:04Speaker 1: You just want to accept a flexible map exactly. Okay,
- 2:07Speaker 1: let me see if I'm tracking this. So building entities
- 2:10Speaker 1: with maps versus records sounds a bit like the difference
- 2:14Speaker 1: between using a giant bin of generic lego bricks versus
- 2:18Speaker 1: a specialized custom molded part.
- 2:20Speaker 2: I'd the way to put it right.
- 2:21Speaker 1: So the generic bricks are maps give you the ultimate
- 2:25Speaker 1: flexibility to snap together any shape you want on the fly.
- 2:29Speaker 1: But the custom part, the record, gives you a highly
- 2:32Speaker 1: predictable shape and presumably better performance.
- 2:35Speaker 2: That analogy holds up beautifully because of what happens inside
- 2:38Speaker 2: the Java Virtual machine I mean closer runs on the JVM.
- 2:41Speaker 2: So when you use a map, the JVM has to
- 2:43Speaker 2: do a lot of dynamic lookups, right.
- 2:45Speaker 1: It's constantly guessing, Yeah.
- 2:47Speaker 2: It has to ask does this key exist? What type
- 2:49Speaker 2: of data is stored here? And that takes processing cycles. Records,
- 2:53Speaker 2: on the other hand, provide class like features with well
- 2:55Speaker 2: known fields. You can use primitive.
- 2:57Speaker 1: Type hints, so you're locking it down exactly.
- 3:00Speaker 2: You are explicitly telling the JVM, hey, this field will
- 3:03Speaker 2: always be a sixty four bit integer. That JVM loves
- 3:07Speaker 2: that predictability. It bypasses the reflective lookups and uses raw
- 3:11Speaker 2: Java arithmetic, which makes operations radically faster.
- 3:15Speaker 1: The source actually uses a space simulation example for this,
- 3:18Speaker 1: which I loved.
- 3:19Speaker 2: Yeah, modeling Earth.
- 3:21Speaker 1: Right if you are modeling Earth, you have attributes like volume, mass,
- 3:25Speaker 1: and ephelion, which is the point farthest from the sun.
- 3:29Speaker 1: If you define that as a record, you lock in
- 3:31Speaker 1: that structure and gain that sheer computational speed for your
- 3:34Speaker 1: orbital physics calculations.
- 3:35Speaker 2: You still have to instantiate those entities, right, and the
- 3:38Speaker 2: text emphasizes that you really should avoid rigid constructors. You
- 3:43Speaker 2: want flexibility, especially when dealing with optional.
- 3:45Speaker 1: Arguments like the Apollo mission example.
- 3:48Speaker 2: They use, Yes, an Apollo mission might have a varying
- 3:50Speaker 2: number of extra vehicular activities or maybe a different number
- 3:53Speaker 2: of orbits planned. Instead of writing ten different constructor functions
- 3:57Speaker 2: for every possible combination of arguments, you just use app destructuring.
- 4:00Speaker 1: I actually want to clarify how map destructuring works for
- 4:03Speaker 1: anyone who hasn't used it heavily. Instead of passing in
- 4:06Speaker 1: a rigid list of variables, you pass in a single
- 4:09Speaker 1: map of options, right, and the constructor functions signature is
- 4:13Speaker 1: designed to reach into that map and elegantly pull out
- 4:16Speaker 1: just the keys it needs, assigning them to local variable.
- 4:19Speaker 2: Yeah. It super clean, and if.
- 4:20Speaker 1: A key like say number of EVAs is missing, the
- 4:24Speaker 1: destructuring syntax can automatically fall back to a default value
- 4:28Speaker 1: without throwing an error, which.
- 4:30Speaker 2: Is incredibly elegant. But and this is a bit but
- 4:33Speaker 2: relying on flexible maps and destructuring introduces a new risk.
- 4:37Speaker 2: We do not have a rigid compile time type checker
- 4:40Speaker 2: yelling at us if someone accidentally passes a string where
- 4:44Speaker 2: a floating point number should be.
- 4:45Speaker 1: Which sounds like a recipe for a catastrophic failure deep
- 4:48Speaker 1: in the application code, long after the bad data was ingested.
- 4:52Speaker 1: So how do we protect the boundaries of our system?
- 4:55Speaker 2: The authors highlight the Prismatic schema library to solve this
- 4:58Speaker 2: exact problem. Schema allows you to explicitly describe the shape
- 5:02Speaker 2: your data must take.
- 5:04Speaker 1: Okay, so it's a gatekeeper exactly.
- 5:06Speaker 2: You can specify that an ingredient list must be a
- 5:09Speaker 2: vector of strings, or that an apolymation must have a
- 5:12Speaker 2: positive integer for its orbit count. You apply the schema
- 5:16Speaker 2: at the boundaries of your system, like when an API
- 5:18Speaker 2: payload arrives.
- 5:19Speaker 1: And it checks it before it gets insidize and validates.
- 5:22Speaker 2: The data at runtime, and if the shape is wrong,
- 5:24Speaker 2: it immediately throws a highly descriptive error message, rather than
- 5:27Speaker 2: letting the bad data poison your database.
- 5:29Speaker 1: Nice. Okay, so we have these perfectly shaped, validated entities.
- 5:34Speaker 1: The next step is behavior. How do we actually operate
- 5:38Speaker 1: on this data? The source contrasts two ways to handle
- 5:41Speaker 1: domain operations, right protocols versus multimethods.
- 5:45Speaker 2: Yeah, so, object oriented languages use polymorphism to attach behavior
- 5:50Speaker 2: to specific types. A dog class has a bark method,
- 5:53Speaker 2: a cat class has a meal method. Enclosure protocols provide
- 5:57Speaker 2: a functional version of this type based dispatch. Ok. Protocols
- 6:00Speaker 2: define a set of functions and you provide specific implementations
- 6:03Speaker 2: for your records. Because they use underlying JVM runtime optimizations,
- 6:08Speaker 2: specifically Java interfaces, they're blazingly fast.
- 6:11Speaker 1: But there's a catch, isn't there always?
- 6:13Speaker 2: The limitation is that protocols only dispatch based on the
- 6:16Speaker 2: type of the first argument provide to the function.
- 6:19Speaker 1: And sometimes the type just isn't enough information to decide
- 6:22Speaker 1: what behavior to execute. The source gives a brilliant example
- 6:25Speaker 1: for multimethods involving a recipe manager.
- 6:28Speaker 2: Application unit conversion one.
- 6:30Speaker 1: Yeah, exactly. Imagine you need to convert units, say pounds
- 6:34Speaker 1: to ounces. A protocol struggles here because pound and ounce
- 6:38Speaker 1: might just be keyword values in a map. Not entirely
- 6:41Speaker 1: different classes.
- 6:42Speaker 2: Right, and multimethods solve this by offering value based dispatch.
- 6:47Speaker 2: Instead of looking at the type, A multimethod runs a
- 6:49Speaker 2: dispatch function on the arguments and uses the resulting value
- 6:53Speaker 2: to decide which specific implementation to run.
- 6:55Speaker 1: Oh wow, so it's looking at the actual data.
- 6:58Speaker 2: Yes, you can inspect the specifics. You're at one method
- 7:01Speaker 2: that executes when the source is pound and the target
- 7:03Speaker 2: is ounce, and a completely different method when the values
- 7:06Speaker 2: are a kilogram and gram. It is infinitely more expressive
- 7:10Speaker 2: than protocols.
- 7:11Speaker 1: But I'm guessing slightly slower.
- 7:12Speaker 2: Yes, slightly slower because of that dynamic evaluation.
- 7:15Speaker 1: Okay, so we have the shape of the data and
- 7:17Speaker 1: we have the behavior. But this leads us to a
- 7:19Speaker 1: massive mind bending hurdle. The real world isn't spatic. It
- 7:24Speaker 1: changes continuously.
- 7:25Speaker 2: It sure does.
- 7:26Speaker 1: So if klojure forces our data to be completely immutable,
- 7:30Speaker 1: how do we reflect a changing world without breaking the
- 7:33Speaker 1: entire simulation. If I can't change the data, how do
- 7:36Speaker 1: I update the system?
- 7:38Speaker 2: The answer requires disentangling two concepts that object oriented programming
- 7:42Speaker 2: usually blurs together, identity and state. The text introduces a
- 7:47Speaker 2: fascinating analogy using e Weird Moobridge's eighteen seventy eight photographs
- 7:52Speaker 2: Sally Gardner at a gallop.
- 7:53Speaker 1: Oh, I've seen that the running horse exactly.
- 7:55Speaker 2: Mowbreed's set up a series of trip wires to take
- 7:58Speaker 2: discrete individual photographs of a horse running. When you view
- 8:01Speaker 2: those static snapshots in rapid sequence, human perception groups them
- 8:05Speaker 2: together to create the illusion of continuous movement.
- 8:08Speaker 1: But traditional object oriented programming approaches this entirely differently. In
- 8:12Speaker 1: in OBIP world, you take one photograph and as the
- 8:14Speaker 1: horse moves, you literally take a paint brush and paint
- 8:17Speaker 1: over the legs on the original photo to update their position.
- 8:20Speaker 2: You're just destroying the old data.
- 8:22Speaker 1: Yeah, you update the data in place, and the authors
- 8:24Speaker 1: argue that mutating data in place is incredibly dangerous.
- 8:27Speaker 2: Because updating data in place erases the dimension of time.
- 8:31Speaker 2: You only ever have the now. If you overwrite the
- 8:33Speaker 2: previous frame, history is gone. You can't look back to
- 8:36Speaker 2: see how the horse was positions a second.
- 8:38Speaker 1: Ago that makes total sense.
- 8:39Speaker 2: Closure avoids this by separating identity and state. Consider the
- 8:44Speaker 2: coffee shop analogy from the text. The identity is the
- 8:47Speaker 2: coffee shop itself, its concept, its location, its brand, over
- 8:51Speaker 2: the years. The state is its exact condition at seven
- 8:55Speaker 2: uarro o am on Tuesday.
- 8:57Speaker 1: Right, So at seven am the state is doors open,
- 9:00Speaker 1: light Rose Brewing, two specific employees.
- 9:03Speaker 2: Working exactly, and at eight pm the state is completely different,
- 9:06Speaker 2: doors lock machines off. The identity of the coffee shop
- 9:09Speaker 2: remains the same, but the state is just a succession
- 9:12Speaker 2: of immutable snapshots.
- 9:13Speaker 1: You don't modify the seven am snapshot.
- 9:16Speaker 2: No, you apply a pure function to it to generate
- 9:18Speaker 2: a brand new eight per ter zero pm snapshot.
- 9:20Speaker 1: Okay, here is where my brain starts flashing red warning lights. Yeah.
- 9:24Speaker 1: If everything is a series of immutable snapshots and we
- 9:28Speaker 1: are generating new states rather than updating them, what happens
- 9:31Speaker 1: when we introduce concurrency?
- 9:33Speaker 2: The traffic jam exactly.
- 9:35Speaker 1: Imagine multiple parts of our program trying to transition the
- 9:38Speaker 1: state of that coffee shop at the exact same millisecond.
- 9:41Speaker 1: One thread wants to sell a coffee, another thread wants
- 9:44Speaker 1: to clock an employee out. Don't we just cause a
- 9:47Speaker 1: massive traffic jam that corrupts the timeline.
- 9:50Speaker 2: Well, that traffic jam is the exact reason manual lock
- 9:53Speaker 2: management in languages like Java and C plus plus is
- 9:56Speaker 2: so notoriously difficult. Threads constantly step on each other, causing
- 10:01Speaker 2: race conditions or deadlocks. It's a nightmare, it really is.
- 10:04Speaker 2: Closure solves this by managing the timeline for you, offering
- 10:08Speaker 2: specific constructs to safely transition state. The source uses a
- 10:12Speaker 2: grocery shopping analogy to explain the escalation of concurrency.
- 10:16Speaker 1: Oh, the single college student versus the family shopping trip.
- 10:19Speaker 1: It is such a hilarious way.
- 10:20Speaker 2: To frame it. It works perfectly, though.
- 10:22Speaker 1: It really does so. If you are a single college
- 10:25Speaker 1: student shopping that represents a single threaded program, it is
- 10:29Speaker 1: incredibly easy. You look at your list, you walk to
- 10:31Speaker 1: the aisle, you put the pizza in your cart. You
- 10:33Speaker 1: don't need to coordinate with anyone because you are the
- 10:35Speaker 1: only one changing the state of the cart.
- 10:37Speaker 2: Right, But the complexity skyrockets when you send a family out,
- 10:42Speaker 2: multiple kids representing multiple threads out into the store to
- 10:45Speaker 2: grab items from a shared list, Chaos is guaranteed.
- 10:49Speaker 1: Total chaos. Two kids might grab the identical item, or.
- 10:52Speaker 2: Someone might sneak candy into the cart without the parents noticing.
- 10:56Speaker 2: You require a mechanism for coordination, close your provide It's
- 11:00Speaker 2: two primary tools for this, atoms and refs.
- 11:03Speaker 1: Let's start with atoms. The text says atoms are for synchronous,
- 11:07Speaker 1: uncoordinated independent state.
- 11:09Speaker 2: Yeah. Imagine you need to update a store's inventory count.
- 11:12Speaker 2: It is a single independent piece of data. You use
- 11:15Speaker 2: a function called swap to apply an update to the atom.
- 11:18Speaker 2: Swap takes your pure function, say, subtract one from inventory,
- 11:22Speaker 2: and tries to apply it. The brilliant part is the
- 11:24Speaker 2: retri mechanism. If thread A and THREADB both try to
- 11:29Speaker 2: buy the item at the exact same time, the atom
- 11:31Speaker 2: lets thread A succeed. When THREADB tries to apply its update,
- 11:36Speaker 2: the atom realizes the underlying state has changed.
- 11:38Speaker 1: Oh so it knows right.
- 11:40Speaker 2: Instead of crashing or corrupting the data, it simply runs
- 11:43Speaker 2: threadbe's pure function again against the new updated inventory number.
- 11:48Speaker 1: But the authors include a major warning here. You must
- 11:51Speaker 1: use a validator function with your atoms. If thread A
- 11:54Speaker 1: and THREADB both run that subtraction function on the last
- 11:56Speaker 1: pack of bacon at the exact same millisecond, the math
- 12:00Speaker 1: we try, but you could end up with an inventory
- 12:02Speaker 1: of negative.
- 12:02Speaker 2: One and absolutely no one wants negative bacon.
- 12:05Speaker 1: No one. So the validator function acts as a final checkpoint.
- 12:08Speaker 1: It evaluates the newly proposed state sees the negative number,
- 12:11Speaker 1: declares it invalid, and aborts the entire change before it
- 12:14Speaker 1: ever becomes the official reality that.
- 12:16Speaker 2: Covers independent state perfectly. But the grocery shopping analogy breaks
- 12:20Speaker 2: down if we only use atoms for complex systems, what
- 12:24Speaker 2: if you need to update multiple things at the exact
- 12:26Speaker 2: same time. This brings us to refs, which use software
- 12:30Speaker 2: transactional memory or STM, which.
- 12:33Speaker 1: They illustrate with the dawdling kid scenario.
- 12:36Speaker 2: Yes, a kid is assigned to get milk. The strict
- 12:39Speaker 2: rules are the item must be marked as a sign,
- 12:42Speaker 2: the milk must be placed in the cart, and absolutely
- 12:44Speaker 2: no candy is allowed to be added. All of these
- 12:47Speaker 2: rules must be enforced together.
- 12:49Speaker 1: So if an atom is like a single bouncer at
- 12:51Speaker 1: the door of a club keeping track of the headcount,
- 12:53Speaker 1: a REF is more like a highly trained team of
- 12:55Speaker 1: bouncers wearing earpieces, coordinating across multiple rooms simultaneously to make
- 13:00Speaker 1: sure nobody sneaks any candy through any door.
- 13:03Speaker 2: That visual perfectly captures the coordination aspect. With refs, you
- 13:07Speaker 2: open a transaction bubble using the dosing function. Inside that bubble,
- 13:11Speaker 2: you use functions like alter and ensure to make changes
- 13:13Speaker 2: to multiple refs at once. The software transactional memory system
- 13:17Speaker 2: executes all of this in a completely isolated alternative timeline.
- 13:21Speaker 1: It is basically playing out a simulation of the changes.
- 13:24Speaker 2: It acts like a database transaction, but entirely in memory.
- 13:28Speaker 2: Before the STM commits those simulated changes back to the
- 13:31Speaker 2: real world, it checks the public timeline. Did any other
- 13:34Speaker 2: thread interfere with any of the refs we were looking
- 13:36Speaker 2: at while we were calculating.
- 13:37Speaker 1: And if they did.
- 13:38Speaker 2: If interference is detected, the STM simply throws away the
- 13:42Speaker 2: alternative timeline, rolls back the transaction, and retries the whole
- 13:46Speaker 2: process from scratch. If the coset is clear, it commits
- 13:50Speaker 2: every single change simultaneously. It is an all or nothing proposition.
- 13:54Speaker 1: That completely eliminates the nightmare of manual lock management. I mean,
- 13:59Speaker 1: we now have perfectly shaped data and we can safely
- 14:01Speaker 1: manage its state across multiple threads without corruption. This means
- 14:05Speaker 1: we are finally ready to unleash the sheer computing power
- 14:08Speaker 1: of a modern multi core processor.
- 14:10Speaker 2: Exactly Historically, processing massive amounts of sequential data enclosure relied
- 14:16Speaker 2: on lazy sequences. You might map a transformation over a
- 14:20Speaker 2: list soil to the results and reduce it down to
- 14:23Speaker 2: a final value. But the source points out a severe
- 14:26Speaker 2: architectural bottleneck With traditional lazy sequences, they are inherently single threaded.
- 14:32Speaker 1: And beyond being single threaded, they create a massive amount
- 14:35Speaker 1: of invisible garbage.
- 14:36Speaker 2: Oh so much garbage.
- 14:37Speaker 1: Yeah. Every time you map or filter over a traditional sequence,
- 14:40Speaker 1: the program is forced to build a temporary intermediate list
- 14:44Speaker 1: in memory just to hand it off to the next step.
- 14:47Speaker 1: If you process a million records, you generate massive intermediate
- 14:50Speaker 1: arrays that trigger the Java garbage.
- 14:52Speaker 2: Collector, which is brutal for a performance.
- 14:55Speaker 1: The garbage collector literally pauses your entire application to clean
- 14:58Speaker 1: up the mess.
- 14:59Speaker 2: To bypass that bottleneck. Closure one point seven introduced transducers.
- 15:03Speaker 2: Transducers separate the transformation the algorithm of what we're doing,
- 15:07Speaker 2: from the input and output mechanisms, which is how we
- 15:10Speaker 2: traverse the data.
- 15:11Speaker 1: Okay, so it uncouples them exactly.
- 15:13Speaker 2: Instead of passing data bucket by bucket down a line
- 15:15Speaker 2: of intermediate lists, transducers compose your maps and filters into
- 15:19Speaker 2: a single algorithmic pipeline. They evaluate each item through the
- 15:23Speaker 2: entire pipeline in one pass, completely eliminating those intermediate garbage.
- 15:27Speaker 1: Lists, but transducers are still fundamentally single threaded. Right if
- 15:31Speaker 1: we want true fine grained parallelism. The source directs us
- 15:35Speaker 1: to reducers.
- 15:36Speaker 2: Yeah, reducers leverage Java's underline fork joint framework. The authors
- 15:40Speaker 2: illustrate this with a shipping company calculated the total weight
- 15:43Speaker 2: of all ground shipments.
- 15:44Speaker 1: How does that work?
- 15:45Speaker 2: The fork joint framework takes a massive collection, splits it
- 15:48Speaker 2: in a half, hands those habs to different CPU cores, splits
- 15:52Speaker 2: them again, processes the math in parallel, and then joins
- 15:56Speaker 2: the results back together.
- 15:57Speaker 1: The performance graphs included in the book are stacked for this.
- 16:01Speaker 1: They tested reducers against regular sequences on small data sets,
- 16:04Speaker 1: say up to five hundred twelve items. Reducers act almost
- 16:07Speaker 1: exactly like regular sequences. The processing time is identical.
- 16:11Speaker 2: But then they scaled it up.
- 16:12Speaker 1: Yeah. When they scaled the test up to one hundred
- 16:15Speaker 1: and thirty one thousand, seventy two items, the reducer automatically
- 16:19Speaker 1: split the workload across the available processor cores. The total
- 16:23Speaker 1: processing time dropped dramatically, almost vertically on the graph, while
- 16:26Speaker 1: the traditional sequence processing time stayed completely flat and slow.
- 16:30Speaker 2: It's pretty amazing to see, but This.
- 16:32Speaker 1: Brings up an obvious architectural question. If reducers are so
- 16:35Speaker 1: incredibly fast and they automatically utilize my multi core processor,
- 16:40Speaker 1: why wouldn't I just use them for absolutely everything? Why
- 16:43Speaker 1: even bother with regular sequences or transducers.
- 16:46Speaker 2: Well, there are strict physical constraints at play. The first
- 16:50Speaker 2: is that five hundred and twelve item threshold you just mentioned.
- 16:53Speaker 2: The operating system incurs a real performance penalty when it
- 16:57Speaker 2: has to spin up a new thread, assign it to
- 16:59Speaker 2: a CPU, and manage the context switching. Oh so it's
- 17:02Speaker 2: not free, not at all. If you are only processing
- 17:05Speaker 2: one hundred items, the time it takes the OS to
- 17:08Speaker 2: organize the threads is actually longer than it would take
- 17:10Speaker 2: a single thread to just do the math sequentially.
- 17:12Speaker 1: The overhead destroys the benefit.
- 17:14Speaker 2: Additionally, reducers only work their parallel magic on specifically foldable
- 17:19Speaker 2: data structures like persistent vectors and maps, where the system
- 17:23Speaker 2: knows exactly how to split them. If you hand a
- 17:25Speaker 2: reducer a standard lazy list, it has to fall back
- 17:28Speaker 2: to using a single thread anyway that makes sense. And lastly,
- 17:32Speaker 2: reducers are eager. They compute everything at once. Sometimes your
- 17:36Speaker 2: architecture actually requires the delayed evaluation of a lazy sequence.
- 17:40Speaker 1: Okay, so we've talked about processing massive batches of data
- 17:43Speaker 1: at rest, But what if our data never stops? What
- 17:47Speaker 1: if our processing is more like an endless assembly line for.
- 17:50Speaker 2: Infinite streams of data, the architecture shifts to core dot async.
- 17:55Speaker 2: This library allows you to build parallel data transformation pipelines.
- 17:59Speaker 2: The text outlines Social Media Sentiment Analyzer to show this right.
- 18:02Speaker 1: Where you have an infinite stream of messages.
- 18:04Speaker 2: Arriving exactly, you use channels to pass the data between
- 18:07Speaker 2: components and go blocks, which are lightweight threadpool backed processes
- 18:12Speaker 2: to analyze the sentiment concurrently.
- 18:13Speaker 1: A critical detail the authors emphasize about core dot ACYNC
- 18:17Speaker 1: channels is that they have strict bounded buffers. They are
- 18:20Speaker 1: never infinite.
- 18:21Speaker 2: Yes, that's crucial.
- 18:22Speaker 1: If a channel can only build ten messages and it
- 18:25Speaker 1: fills up, the component trying to push the eleventh message
- 18:28Speaker 1: is forced to pause, it creates back pressure, immediately forcing
- 18:32Speaker 1: the system to slow down its intake, rather than letting
- 18:35Speaker 1: a cbe balloon in memory until the server violently crashes
- 18:38Speaker 1: at three.
- 18:38Speaker 2: Am, because nobody wants that three am page or duty.
- 18:42Speaker 2: Bounded buffers force resilient design. Let's look at the complete picture.
- 18:46Speaker 2: We have isolated our data entities into maps and records.
- 18:49Speaker 2: We have secured our state using the SPM. We have
- 18:51Speaker 2: weaponized our multi core processors using transducers, reducers and core
- 18:56Speaker 2: dot async.
- 18:57Speaker 1: The final hurdle is taking all these disparate spinning gears
- 19:00Speaker 1: and assembling them into a coherent machine.
- 19:02Speaker 2: Right. Because you cannot just have hundreds of pure functions
- 19:05Speaker 2: and channels floating around to chaotic void. You need a
- 19:08Speaker 2: structured architecture. The text introduces Stuart Seer's Component library as
- 19:13Speaker 2: the solution for organizing namespaces and managing application state.
- 19:16Speaker 1: Because without a rigid structure, developers often fall into the
- 19:20Speaker 1: trap of circular dependencies right where namespace A requires namespace B,
- 19:24Speaker 1: which requires name space A, and then the application refuses
- 19:28Speaker 1: to compile exactly.
- 19:30Speaker 2: The component library forces a disciplined anatomy. Every component consists
- 19:34Speaker 2: of three distinct elements, its configuration, its internal runtime state,
- 19:40Speaker 2: and its explicit dependencies on other components.
- 19:43Speaker 1: The social media monitoring architecture detailed in the text showcases
- 19:46Speaker 1: this beautifully. The system is broken down into distinct, specialized components.
- 19:51Speaker 1: You start with the feed component, right.
- 19:53Speaker 2: The intake.
- 19:53Speaker 1: Its entire existence is dedicated purely to managing the external
- 19:57Speaker 1: connection to Twitter or Facebook. It is absolutely no business logic.
- 20:00Speaker 1: It just opens the socket and streams data in, and
- 20:03Speaker 1: then that.
- 20:03Speaker 2: Raw data flows into the knowledge Engine component. This is
- 20:06Speaker 2: the brain. It holds the business rules, processes the feed,
- 20:10Speaker 2: evaluate sentiment, and fires off alerts.
- 20:12Speaker 1: Finally, those alerts travel to the approvals component, which notifies
- 20:16Speaker 1: the human operators. The operators can then adjust the rules,
- 20:19Speaker 1: feeding those updates back into the Knowledge.
- 20:21Speaker 2: Engine and the component library system MAP manages this entire
- 20:25Speaker 2: complex life cycle. It uses explicit start and stop functions.
- 20:30Speaker 2: Because you declare the dependencies up front, the library knows
- 20:33Speaker 2: the exact topological order to boot the system.
- 20:36Speaker 1: So it's smart about the startup sequence.
- 20:39Speaker 2: Very smart. It starts the knowledge engine first, ensures it
- 20:42Speaker 2: is healthy, and only then starts the feed component and
- 20:45Speaker 2: injects the engine into it as a dependency. It completely
- 20:49Speaker 2: eradicates those maddening circular reference errors.
- 20:52Speaker 1: I noticed in the source texts that components don't always
- 20:54Speaker 1: call each other's functions directly. Often they communicate by passing
- 20:58Speaker 1: core dot async channels between them. At first glance, injecting
- 21:02Speaker 1: a channel between the feed and the knowledge engines seems
- 21:04Speaker 1: like adding unnecessary complexity. Why not just have the feed
- 21:07Speaker 1: component directly call a process function on the engine.
- 21:10Speaker 2: Well, direct function calls create rigid coupling. If the feed
- 21:15Speaker 2: calls the engine directly, the feed's execution thread is blocked
- 21:18Speaker 2: until the engine finishes processing. By placing a bounded channel
- 21:22Speaker 2: between them, you achieve ultimately coupling.
- 21:24Speaker 1: Oh I see, the.
- 21:25Speaker 2: Feed can rapidly pull data off the network and drop
- 21:28Speaker 2: it into the channel at its own pace. If a
- 21:30Speaker 2: massive spike in traffic bogs down the knowledge engine, the
- 21:33Speaker 2: channel fills up, creating that back pressure we discussed earlier.
- 21:36Speaker 1: And then the channel signals the feed to pause its
- 21:39Speaker 1: network intick exactly.
- 21:40Speaker 2: The components remain totally ignorant of each other's implementation details,
- 21:44Speaker 2: resulting in a highly elastic, resilient system.
- 21:47Speaker 1: Wow. We started this deep dive staring at a terrifying
- 21:51Speaker 1: blank screen wondering how to construct enterprise grade software. We
- 21:56Speaker 1: chiseled out perfect immutable entities. We safely manage the stay
- 22:00Speaker 1: across time entirely bypassing the concurrency bugs that ruin object
- 22:04Speaker 1: oriented systems.
- 22:05Speaker 2: It's quite a journey.
- 22:06Speaker 1: We harnessed multi core parallelism to process massive data streams,
- 22:10Speaker 1: and finally we assembled those pieces into a clean, decoupled
- 22:14Speaker 1: component architecture.
- 22:15Speaker 2: This architectural journey is really the shortcut to mastering production systems.
- 22:20Speaker 2: Closure's constraints, the strict immutability, the managed state transitions, the
- 22:24Speaker 2: pure functions. I mean, they might feel restrictive at first,
- 22:28Speaker 2: but they are designed to set you free.
- 22:29Speaker 1: They handle the chaos so you don't have to.
- 22:31Speaker 2: Right They handle the chaos of concurrency so you can
- 22:34Speaker 2: focus entirely on the actual business logic.
- 22:36Speaker 1: It requires a profound shift in how you view the world,
- 22:39Speaker 1: though the source text makes it clear that closure forces
- 22:42Speaker 1: developers to model reality as a series of discrete, immutable snapshots,
- 22:47Speaker 1: just like the frames of Muwbridge's film, history is never overridden.
- 22:51Speaker 1: It is preserved as a sequence of unchangeable facts.
- 22:54Speaker 2: And taking that philosophy a step further, it poses a
- 22:57Speaker 2: pretty profound question for the future as the digital systems
- 23:00Speaker 2: that govern our financial, social, and logistical lives increasingly adopt
- 23:04Speaker 2: this architecture. Viewing human history purely as a sequence of unchangeable,
- 23:08Speaker 2: verifiable snapshots, I mean, it fundamentally changes how data is perceived, and.
- 23:13Speaker 1: As artificial intelligence systems train on those architectures, how might
- 23:16Speaker 1: that shape their understanding of human memory and growth. If
- 23:19Speaker 1: an AI's worldview is built entirely on immutable, discrete snapshots,
- 23:24Speaker 1: does it view our past with perfect, unforgiving clarity, or
- 23:28Speaker 1: does it lose the blurry, continuous nature of what it
- 23:31Speaker 1: actually means to be human? Something for you to mull
- 23:33Speaker 1: over the next time you are staring at that blank screen.
- 23:36Speaker 1: Remember you aren't just writing code. You are laying down
- 23:39Speaker 1: the tracks of time, one immutable snapshot at a time.