Latest / CyberSecurity Summary / Client-Side Data Storage: Keeping It Local
Transcript
- 0:00Speaker 1: So imagine you have a friend, a friend that you
- 0:03Speaker 1: visit every single day. Okay, sounds nice, right, But you
- 0:06Speaker 1: walk up to their house, you knock on the door,
- 0:07Speaker 1: they open it, and they just stare at you completely blankly.
- 0:10Speaker 2: Oh wow, yeah.
- 0:11Speaker 1: Totally blank. You have tell them your name, your favorite food,
- 0:15Speaker 1: where you work, and exactly why you're standing on their
- 0:18Speaker 1: porch every single day.
- 0:21Speaker 2: That sounds incredibly exhausting and you know, highly inefficient.
- 0:26Speaker 1: Exactly, but that is exactly how the traditional internet works.
- 0:29Speaker 1: Every time you load a web page, the browser acts
- 0:32Speaker 1: like it's meeting the server for the very first time.
- 0:34Speaker 1: Complete amnesia.
- 0:35Speaker 2: Yeah, it's a fundamental flaw in the original design.
- 0:39Speaker 1: So welcome to the deep Dive. I'm your host, and
- 0:41Speaker 1: today our mission is to cure the browser's amnesia.
- 0:45Speaker 2: And as the resident expert today, I'm excited to get
- 0:47Speaker 2: into this.
- 0:48Speaker 1: Yeah. We are pulling insights today from Raymond Camden's book
- 0:52Speaker 1: it's called Client Side Data Storage, Keeping It Local, published
- 0:55Speaker 1: by O'Reilly. We are exploring how to finally give the
- 0:58Speaker 1: browser a permanent memory.
- 1:00Speaker 2: Which I mean it fundamentally changes how we interact with
- 1:03Speaker 2: the web because traditionally, you know, browsers just ask for
- 1:06Speaker 2: documents and server send them back right. That simple transaction
- 1:09Speaker 2: is the entire relationship. But by storing data locally, like
- 1:13Speaker 2: right on your hard drive, we flip that dynamic. We
- 1:16Speaker 2: turn the browser into its own standalone engine, and.
- 1:19Speaker 1: The performance gains alone just make this totally worth unpacking
- 1:22Speaker 1: for you all listening, because when data is local, you
- 1:25Speaker 1: get immediate access exactly, you weren't waiting for a signal
- 1:28Speaker 1: to you know, travel across the country to some database
- 1:30Speaker 1: and then come all the way back.
- 1:32Speaker 2: Yeah. And you also drastically reduce the strain on the
- 1:34Speaker 2: back end infrastructure. I mean, if a server isn't constantly
- 1:38Speaker 2: fetching the exact same user preferences thousands of times a minute.
- 1:42Speaker 1: It can actually do real work, right.
- 1:44Speaker 2: It can devote its compute power to complex business logic
- 1:48Speaker 2: and well, the holy grail of all this local data
- 1:51Speaker 2: storage is the fully offline web application, of.
- 1:54Speaker 1: The offline app the dream.
- 1:56Speaker 2: Exactly, you can build apps that just keep working even
- 2:00Speaker 2: when you drive into a tunnel and drop your cell signal.
- 2:03Speaker 1: But you know, I always look for the catch when
- 2:06Speaker 1: a technology promises the holy grail, And based on the sources,
- 2:10Speaker 1: it seems like the biggest hurdle is that none of
- 2:13Speaker 1: these core technologies have built in synchronization with the cloud.
- 2:18Speaker 2: That is the massive catch. Handling conflict resolution is entirely
- 2:21Speaker 2: on you, as.
- 2:22Speaker 1: The developer, So it's not magic, not at all.
- 2:25Speaker 2: If a user changes data in their browser while offline
- 2:29Speaker 2: and someone else modifies that same record on the server,
- 2:32Speaker 2: you have to write the logic to merge those changes
- 2:35Speaker 2: or you know, pick a winner.
- 2:37Speaker 1: That sounds messy, it can be.
- 2:39Speaker 2: And beyond that, the storage limits across different browsers are
- 2:41Speaker 2: just frustratingly fuzzy fuzzy.
- 2:43Speaker 1: How Like, they don't tell you.
- 2:44Speaker 2: The limit pretty much. You rarely get a hardcap. Yeah,
- 2:47Speaker 2: the browser simply evicts old data when the drive gets
- 2:50Speaker 2: too full, and it bases that on its own opaque algorithms.
- 2:53Speaker 1: Yikes.
- 2:54Speaker 2: Yeah. And finally, you have to remember these tools are
- 2:57Speaker 2: not a replacement for a heavy duty embedded database like Oracle.
- 3:01Speaker 1: Right, so you still need to use the right tool
- 3:03Speaker 1: for the right job. I like to frame this evolution
- 3:05Speaker 1: kind of like upgrading an office. So we're going to
- 3:08Speaker 1: start by looking at the browser's original memory system, which
- 3:11Speaker 1: is basically a tiny, highly inefficient sticky.
- 3:14Speaker 2: Note A very apt analogy yeah.
- 3:16Speaker 1: And by the end we are going to build a massive,
- 3:19Speaker 1: highly organized asynchronous filing cabinet.
- 3:22Speaker 2: I love that. So let's start with that tiny sticky
- 3:24Speaker 2: note that represents the oldest technology in the book, which
- 3:27Speaker 2: is cookies.
- 3:28Speaker 1: Cookies.
- 3:28Speaker 2: Yeah, they date all the way back to a Netscape
- 3:32Speaker 2: beta in nineteen ninety four.
- 3:34Speaker 1: Wow, nineteen ninety four.
- 3:35Speaker 2: Right, so they carry the immense baggage of how the
- 3:37Speaker 2: web used to work. They function essentially as just small
- 3:40Speaker 2: text value sent back and forth via HTTP headers.
- 3:44Speaker 1: And here's where I have to like really push back
- 3:46Speaker 1: on the entire premise of using cookies for storage, because
- 3:50Speaker 1: if the whole goal of client size storage is to
- 3:52Speaker 1: keep data off the network to save bandwidth, cookies defeat
- 3:56Speaker 1: the entire purpose, oh one hundred percent. The sources explicitly
- 3:59Speaker 1: state they could sent on every single HTTPU request in response.
- 4:03Speaker 2: Every single one. Whether you are asking for a massive
- 4:06Speaker 2: HTML document or just you know, pinging the server for
- 4:09Speaker 2: a tiny fabricon image, it.
- 4:10Speaker 1: Doesn't matter, right. The browser diligently packages up all your
- 4:15Speaker 1: cookies for that domain and attaches them to the header
- 4:18Speaker 1: of their request.
- 4:19Speaker 2: It is the equivalent of writing your personal preferences on
- 4:22Speaker 2: a heavy brick and then mailing that brick back and
- 4:25Speaker 2: forth to a store every time you want to ask
- 4:27Speaker 2: them a simple question.
- 4:28Speaker 1: That's a great way to put it.
- 4:29Speaker 2: Like you asked, hey, do you have this shirt and blue?
- 4:32Speaker 2: And you mail the heavy brick. They reply, yes, we do,
- 4:34Speaker 2: and they mail the exact same brick back to you.
- 4:37Speaker 2: The network drag is just absurd.
- 4:38Speaker 1: It is, and developers have absolutely abused that mechanism over
- 4:43Speaker 1: the decades. So browsers eventually had to impose limits.
- 4:46Speaker 2: Well kind of limits.
- 4:47Speaker 1: Well, you're generally restricted to about fifty cookies per domain
- 4:52Speaker 1: and a total size limit of just four kilobytes across
- 4:56Speaker 1: all of them.
- 4:56Speaker 2: Four kilobytes.
- 4:57Speaker 1: That's nothing, it's kiny.
- 4:59Speaker 2: But the author actually decided to stress test those limits,
- 5:01Speaker 2: which I love. The results were hilarious.
- 5:03Speaker 1: Oh, this is a great story. Yeah.
- 5:05Speaker 2: He pushed over four hundred cookies into the Google Chrome
- 5:08Speaker 2: browser just to see what would break first, and Chrome
- 5:11Speaker 2: handled the massive volume perfectly. Fine, It didn't stutter at all. Right,
- 5:15Speaker 2: the browser was fine. The web server he was talking to, however,
- 5:18Speaker 2: completely crashed.
- 5:20Speaker 1: Wait really it took down the server.
- 5:22Speaker 2: Yeah, because Apache and in Jank's web servers have limits
- 5:25Speaker 2: on it's a security thing to prevent denial of service attacks.
- 5:31Speaker 1: Oh, that makes sense.
- 5:32Speaker 2: So by bloating the requests with hundreds of cookies, the
- 5:36Speaker 2: client effectively dedossed its own server.
- 5:38Speaker 1: That is wild.
- 5:39Speaker 2: The server just couldn't parch the sheer volume of header data,
- 5:42Speaker 2: so it failed.
- 5:43Speaker 1: So we have this tiny four killed by capacity massive
- 5:47Speaker 1: network bloat. And to make matters even worse, the API
- 5:50Speaker 1: for writing a cookie is incredibly clunky.
- 5:53Speaker 2: Oh it's terrible.
- 5:54Speaker 1: Like the set of cookie, you assign a string to
- 5:56Speaker 1: document dot cookie, so you write something like document dot
- 5:59Speaker 1: cookie Raymond. Simple enough, right, sure. But then to set
- 6:03Speaker 1: a second cookie you just run the exact same assignment
- 6:05Speaker 1: document dot cookie age forty three.
- 6:07Speaker 2: Which is wild because in almost any other programming paradigm,
- 6:11Speaker 2: assigning a new value to an existing variable overwrites the
- 6:15Speaker 2: old one.
- 6:15Speaker 1: Right if x equals one and then x equals two,
- 6:18Speaker 1: axes two exactly.
- 6:20Speaker 2: But the document dot cookie API magically appends it instead.
- 6:24Speaker 2: It violates basic programming intuition.
- 6:26Speaker 1: And reading them is a total nightmare of string parsing.
- 6:30Speaker 1: You ask for document dot cookie and the browser just
- 6:33Speaker 1: spits back one giant, messy string of texts with all
- 6:36Speaker 1: your cookies separated by semi collins.
- 6:38Speaker 2: Yeah, you are basically forced to write your own regular
- 6:40Speaker 2: expressions just to chop that string up and find this
- 6:43Speaker 2: specific piece of data you actually want and deleting them.
- 6:46Speaker 1: Deleting them requires an absurd workaround. You can't simply invoke
- 6:50Speaker 1: a delete command.
- 6:51Speaker 2: Yeah, that would be too easy.
- 6:52Speaker 1: You literally must reset the cookie with an expiration date.
- 6:55Speaker 1: In the past, developers traditionally used January first, nineteen seventy,
- 7:00Speaker 1: the Unix epoch.
- 7:01Speaker 2: Yeah, you are essentially forced to time travel just to
- 7:03Speaker 2: kill a tech string.
- 7:04Speaker 1: It's so hacky. So if cookies are basically a network
- 7:07Speaker 1: tax that we want to avoid, where are developers actually
- 7:10Speaker 1: putting this data today? I mean, I know I'm not
- 7:12Speaker 1: mailing a brick every time I use an offline text
- 7:14Speaker 1: editor in my browser. We clearly threw away the sticky
- 7:17Speaker 1: note and bought a real local locker.
- 7:19Speaker 2: We did. The industry shifted to web storage, which is
- 7:23Speaker 2: almost universally known as local storage.
- 7:25Speaker 1: Okay, the upgrade right.
- 7:27Speaker 2: It gives you roughly five to ten megabytes of space,
- 7:30Speaker 2: depending on the browser vendor, And crucially, this data never
- 7:34Speaker 2: touches the network automatically.
- 7:36Speaker 1: That's the key.
- 7:36Speaker 2: Yeah, it stays quietly on the local machine until your
- 7:39Speaker 2: JavaScript explicitly asks for it.
- 7:42Speaker 1: And it provides two distinct flavors. Right. Local storage persists
- 7:45Speaker 1: forever until you intentionally clear it, and session storage dies
- 7:48Speaker 1: the second you close the browser tab.
- 7:51Speaker 2: Exactly, and the mechanics are beautifully simple compared to the
- 7:54Speaker 2: cookie nightmare. You only have four clear commands, which are
- 7:58Speaker 2: you've got set item to save data, get item to
- 8:02Speaker 2: read it, remove item to delete a specific entry, and
- 8:05Speaker 2: clear to wipe the whole locker.
- 8:06Speaker 1: It is so much cleaner it is.
- 8:08Speaker 2: Security is also baked in. Local storage is strictly scoped
- 8:12Speaker 2: to the domain, so if you save a preference on
- 8:14Speaker 2: food dot com, a script running on Goo dot com
- 8:17Speaker 2: cannot peek into that storage.
- 8:18Speaker 1: Locker makes total sense, but the sources do warn about
- 8:21Speaker 1: a specific limitation here, which they call the string trap.
- 8:24Speaker 2: Ah. Yes, the string.
- 8:27Speaker 1: Trap, because web storage only holds strings. I know the
- 8:30Speaker 1: standard workaround is to run objects through Jason dot stringify
- 8:34Speaker 1: before saving them, but the text implies there's a much
- 8:37Speaker 1: bigger issue here than just you know, typing a few
- 8:40Speaker 1: extra characters to encode an array.
- 8:42Speaker 2: You're right, The hidden tax here is CPU cycles and threadblocking.
- 8:45Speaker 1: Thread blocking. Yeah.
- 8:47Speaker 2: If you have a massive, complex JavaScript object, maybe a
- 8:52Speaker 2: deeply nested user profile with thousands of relational data points,
- 8:55Speaker 2: and you try to save it to local storage, the
- 8:58Speaker 2: browser has to serialize the entire object into a text string, right,
- 9:03Speaker 2: and Jason stringify is a synchronous operation. It blocks the
- 9:05Speaker 2: main thread.
- 9:06Speaker 1: Oh oh wow. So while the browser is busy converting
- 9:09Speaker 1: say five megabytes of application state into a massive text string, yeah,
- 9:13Speaker 1: the user's interface completely freezes completely.
- 9:16Speaker 2: They can't scroll, they can't click buttons, animations stutter and stop.
- 9:19Speaker 1: That's terrible user experience.
- 9:21Speaker 2: It's really bad. And the same penalty applies on the
- 9:23Speaker 2: way out. When you pull that five megabyte string back
- 9:26Speaker 2: out of local storage, Jason Pars has to reconstruct the
- 9:29Speaker 2: object synchronously.
- 9:30Speaker 1: So it freezes again.
- 9:31Speaker 2: Exactly. So, for simple preferences, the string trap is trivial,
- 9:35Speaker 2: but for state heavy web applications it creates a massive
- 9:38Speaker 2: performance bottleneck.
- 9:40Speaker 1: That makes perfect sense. Okay, before we move on from
- 9:42Speaker 1: local storage, we have to talk about the storage event.
- 9:45Speaker 2: Yes, this is a fun one.
- 9:47Speaker 1: Because you can attach an event listener to the window
- 9:50Speaker 1: object that fires whenever the data in local storage changes.
- 9:54Speaker 1: But the twist absolutely baffled me at first glance.
- 9:57Speaker 2: Which part.
- 9:58Speaker 1: If I have a tab open and I type something
- 10:00Speaker 1: into a form that updates local storage, the event ignores
- 10:04Speaker 1: the tab that made the change, it just doesn't fire.
- 10:06Speaker 2: I know, it seems totally counterintuitive until you know you
- 10:09Speaker 2: look at the architectural purpose of the event.
- 10:11Speaker 1: Okay, lay it on me.
- 10:12Speaker 2: The tab that initiated the change already knows the data
- 10:15Speaker 2: was updated because it executed the code itself. The storage
- 10:19Speaker 2: event is strictly designed for cross tab communication.
- 10:22Speaker 1: Wait, if I have two tabs open, Hey, aren't they
- 10:24Speaker 1: aggressively sandbox from each other for security? How does tab
- 10:28Speaker 1: B even no tab A touched the local storage. Is
- 10:32Speaker 1: the browser itself acting like a local pub sub message broker.
- 10:36Speaker 2: That is the absolute perfect way to visualize it. The
- 10:40Speaker 2: browser acts as the central message broker.
- 10:42Speaker 1: Wow.
- 10:43Speaker 2: Imagine you have two tabs open to the exact same
- 10:46Speaker 2: shopping application. In tab A, you click add to cart. Okay,
- 10:50Speaker 2: the application saves the new cart state to local storage
- 10:54Speaker 2: because the storage for that domain was modified. The browser's
- 10:57Speaker 2: internal pub subsystem broadcast ask the storage event to tab B,
- 11:02Speaker 2: and the.
- 11:02Speaker 1: Event payload even includes the old value and the new
- 11:06Speaker 1: value exactly so TABB can inspect the payload, see the
- 11:09Speaker 1: new item, and instantly update the little cart icon in
- 11:13Speaker 1: its own navigation bar.
- 11:14Speaker 2: Yep, you have synchronized to completely separate sandbox tabs in
- 11:18Speaker 2: real time without sending a single byte of data to
- 11:20Speaker 2: a server.
- 11:21Speaker 1: That is incredible cool. It makes the web feel alive
- 11:23Speaker 1: and responsive, it really does.
- 11:25Speaker 2: But you know, as we discuss with the string FORRAPP,
- 11:27Speaker 2: local storage hits a wall when you need to store
- 11:29Speaker 2: complex or massive data set.
- 11:31Speaker 1: Right because of the UI freezing.
- 11:32Speaker 2: Yeah, the ten megabyte capacity and the synchronous main thread
- 11:36Speaker 2: blocking nature of the API. I mean we eventually need
- 11:38Speaker 2: a heavy duty solution.
- 11:39Speaker 1: We need the massive filing cabinet, which brings us to
- 11:42Speaker 1: index dB. This is the deep end of the pool
- 11:45Speaker 1: for client side storage.
- 11:46Speaker 2: It really is.
- 11:47Speaker 1: It handles massive data sets and operates entirely asynchronously, meaning
- 11:52Speaker 1: it does all its heavy lifting on background threads without
- 11:55Speaker 1: freezing the user interface.
- 11:57Speaker 2: Which is exactly what we want. But it is incredibly powerful,
- 12:01Speaker 2: and it earned a reputation for having a notoriously unfriendly API.
- 12:05Speaker 1: Unfriendly is an understatement. The sources mentioned that historically support
- 12:09Speaker 1: for index dB on iOS eight was so fundamentally broken
- 12:12Speaker 1: that developers literally wrote regular expression scripts to sniff out
- 12:17Speaker 1: Apple mobile.
- 12:17Speaker 2: Devices, Oh the dark days of web development.
- 12:20Speaker 1: Like if the rejects matched an iPhone, the code just
- 12:22Speaker 1: pretended indexdb didn't exist at all and fell back to
- 12:25Speaker 1: older tech what was actually breaking under the hood to
- 12:28Speaker 1: force that kind of extreme workaround.
- 12:30Speaker 2: So webkits early implementation of indexdb on iOS was tied
- 12:34Speaker 2: to a very clumsy, squee light backing store, and the
- 12:37Speaker 2: translation between the asynchronous object oriented nature of index dB
- 12:41Speaker 2: and the rigid synchronous nature of the underlying SQL database
- 12:44Speaker 2: was deeply flawed.
- 12:45Speaker 1: How bad was it?
- 12:46Speaker 2: Terrible? Developers experienced catastrophic data loss cursors, skipping records, and
- 12:51Speaker 2: just totally unpredictable crashes.
- 12:53Speaker 1: So they just bypassed it entirely.
- 12:55Speaker 2: I mean I would too, Yeah, exactly. Thankfully, the browser
- 12:59Speaker 2: engines have mature lot and the modern support is highly reliable,
- 13:03Speaker 2: but the architecture still requires a huge mental shift, especially
- 13:07Speaker 2: if you are coming from traditional relational databases like Micequel right.
- 13:10Speaker 1: Because you do not have SQL tables with rigid predefined columns.
- 13:15Speaker 2: Instead, index dB uses databases at the top level, and
- 13:18Speaker 2: inside those you create object stores.
- 13:21Speaker 1: So the database is the filing cabinet. The object store
- 13:24Speaker 1: is a specific drawer. You might have one drawer labeled
- 13:28Speaker 1: users and another labeled invoices exactly, but inside that drawer
- 13:32Speaker 1: it is a schemless free for all because it stores
- 13:35Speaker 1: raw JavaScript objects natively, avoiding that gson dot string of
- 13:38Speaker 1: fy tex we talked about earlier. Yeah, you can throw
- 13:41Speaker 1: wildly different data shapes into the exact same object store. Yeah.
- 13:44Speaker 2: The author gives a brilliant example of this flexibility. You
- 13:47Speaker 2: could insert a user record where the age property is
- 13:50Speaker 2: an integer like the number forty two, and in the
- 13:53Speaker 2: very next record the age property could be the literal
- 13:56Speaker 2: texturing tool to matter and index dB accepts both without
- 14:00Speaker 2: throwing a single scheme of validation error.
- 14:03Speaker 1: But the obvious question is, just because the database lets
- 14:06Speaker 1: you mix data shapes natively, does that mean you should
- 14:08Speaker 1: actually design your applications that way?
- 14:10Speaker 2: Oh? Absolutely not. Structure is still paramount for maintainability even
- 14:14Speaker 2: without rigid columns. Every single record you place into an
- 14:17Speaker 2: object store must be identifiable by a primary key, right.
- 14:21Speaker 2: The database needs a unique identifier to fetch or update
- 14:25Speaker 2: that specific record later, And.
- 14:27Speaker 1: The API gives you two distinct ways to handle that, right,
- 14:30Speaker 1: a keypath or key generator.
- 14:32Speaker 2: That's right.
- 14:32Speaker 1: So if I am storing user profiles that inherently contain
- 14:36Speaker 1: unique email addresses or say, social security numbers, I assume
- 14:39Speaker 1: I would use a key path exactly.
- 14:41Speaker 2: You instruct the database to look inside the data payload itself.
- 14:44Speaker 2: You define the keypath as the email property, and index
- 14:47Speaker 2: dB automatically extracts that value to use as the primary
- 14:51Speaker 2: key for the index.
- 14:53Speaker 1: Got it. But if I'm just saving random offline drafts
- 14:56Speaker 1: of blog posts, the data doesn't really have a natural
- 14:59Speaker 1: unique idea. I need the database to handle it for me.
- 15:02Speaker 2: And that is the precise use case for a key generator.
- 15:05Speaker 2: You can figure the object store to auto increment a
- 15:08Speaker 2: numerical ID.
- 15:09Speaker 1: Oh nice, Yeah, every.
- 15:10Speaker 2: Time you hand in a new draft, it assigns it
- 15:12Speaker 2: ID one than ID two. Maintaining uniqueness automatically behind the scenes.
- 15:17Speaker 1: And finding those records later requires creating indexes so you
- 15:20Speaker 1: don't have to scan the entire drawer sequentially. You can
- 15:23Speaker 1: index by date, by author, by status.
- 15:26Speaker 2: Yep. It makes searching incredibly fast, But.
- 15:29Speaker 1: The sources highlight a very strict security and structural rule here.
- 15:33Speaker 1: You cannot just inject new object stores or create new
- 15:37Speaker 1: indexes on the fly, whatever your application code feels like.
- 15:40Speaker 2: No, you are restricted from modifying the schema. Loosely, you
- 15:43Speaker 2: can only alter the structure of your database during a
- 15:46Speaker 2: highly specific browser event called upgrade needed.
- 15:49Speaker 1: So if I build an application today and three months
- 15:52Speaker 1: from now, I deploy an update that requires a new
- 15:55Speaker 1: object store for user uploaded images, what is stopping my
- 16:02Speaker 1: jobscript from just creating that drawer instantly?
- 16:04Speaker 2: Concurrency conflicts and data corruption.
- 16:07Speaker 1: Ah.
- 16:07Speaker 2: Imagine a scenario where the user has two tabs open.
- 16:11Speaker 2: Tab A is currently writing massive amounts of data into
- 16:14Speaker 2: an object store.
- 16:15Speaker 1: Okay.
- 16:16Speaker 2: Meanwhile, the code in tab B decides it wants to
- 16:19Speaker 2: delete that entire object store and replace it.
- 16:21Speaker 1: That sounds like a disaster.
- 16:23Speaker 2: It is. The database would be left in a completely
- 16:25Speaker 2: corrupted state.
- 16:26Speaker 1: So the browser forces version control.
- 16:28Speaker 2: Precisely by requiring you to bump the version number of
- 16:31Speaker 2: the database, say from version one to version two. The
- 16:34Speaker 2: browser intercepts the request and fires the upgrade needed event.
- 16:37Speaker 1: And what does that do?
- 16:38Speaker 2: It acts as an exclusive lock. It forces all other
- 16:41Speaker 2: active connections in other tabs to close or pause before
- 16:44Speaker 2: granting you the one and only window to safely remodel
- 16:46Speaker 2: the filing cabinet. Wow okay, yeah, and once the upgrade
- 16:49Speaker 2: needed event finishes, the new structure is locked into place.
- 16:52Speaker 1: That forces incredible intentionality on the developer. You really have
- 16:56Speaker 1: to plan ahead, you do.
- 16:57Speaker 2: And speaking of safety mechanisms, all all the actual interactions
- 17:01Speaker 2: with the data, creating, reading, updating, deleting must happen inside
- 17:05Speaker 2: a transaction.
- 17:06Speaker 1: And the transaction acts as an atomic safety wrapper around
- 17:09Speaker 1: your database operations. Like if you attempt to update five
- 17:13Speaker 1: relational records and a script error occurs where the device
- 17:16Speaker 1: loses power right as the fourth record is being modified,
- 17:20Speaker 1: the transaction fails entirely exactly.
- 17:23Speaker 2: The database doesn't just leave the first three changes sitting
- 17:26Speaker 2: there in a half finished state. It automatically rolls back
- 17:29Speaker 2: all the operations to ensure the data remains pristine and consistent.
- 17:33Speaker 1: It's an all or nothing approach.
- 17:34Speaker 2: Total data integrity and moving from writing data to reading
- 17:38Speaker 2: it introduces another fascinating mechanism, Oh the beaver. Yes, when
- 17:42Speaker 2: you need to fetch massive amounts of data, say you
- 17:45Speaker 2: want to retrieve all one hundred thousand historical temperature reading
- 17:49Speaker 2: stored in the database, you do not just run a
- 17:51Speaker 2: query and dump all one hundred thousand records into an.
- 17:53Speaker 1: Array, right, because doing so would immediately overflow the browser's
- 17:57Speaker 1: available RAM and crash the tab Ooh, we have to
- 18:01Speaker 1: stream it. And the API uses a tool called a cursor,
- 18:05Speaker 1: and the author uses an incredible analogy to explain how
- 18:08Speaker 1: it operates. A cursor is not a blinking line on
- 18:11Speaker 1: a screen. It is a happy little beaver.
- 18:14Speaker 2: It visualizes the iteration process so perfectly. Instead of loading
- 18:18Speaker 2: the entire data set into memory, the cursor fetches one
- 18:22Speaker 2: record at a time.
- 18:23Speaker 1: The happy little beaver runs into the object store, grabs
- 18:26Speaker 1: a very first temperature reading, scurries back out, drops it
- 18:29Speaker 1: at your JavaScript's feet, and pauses.
- 18:31Speaker 2: Good beaver.
- 18:32Speaker 1: Right. It waits for you to process the data, render
- 18:34Speaker 1: it to the screen or calculated average. Once you are done,
- 18:37Speaker 1: you tell the cursor to continue, and the beaver runs
- 18:39Speaker 1: back in to fetch the second record.
- 18:41Speaker 2: It streams the data sequentially. You can instruct the cursor
- 18:45Speaker 2: to iterate backward or to only fetch records that fall
- 18:47Speaker 2: within a specific date range index, ensuring you process large
- 18:51Speaker 2: data sets with minimal memory overhead.
- 18:53Speaker 1: We have covered a massive architectural shift today from tiny
- 18:57Speaker 1: text strings to asynchronous Beaver's managing gigables of local storage.
- 19:01Speaker 1: Synthesizing this toolkit really requires understanding when to deploy each
- 19:06Speaker 1: technology exactly.
- 19:07Speaker 2: So to break it down, cookies should be relegated almost
- 19:11Speaker 2: entirely to legacy authentication tokens or data the server explicitly
- 19:15Speaker 2: mandates to see on every single network request.
- 19:18Speaker 1: Basically, leave the heavy brick at home to save bandwidth, please.
- 19:22Speaker 2: Do step up to local storage for quick synchronous interface
- 19:25Speaker 2: state basic Jason preferences and utilizing that brilliant Crosstab messaging system.
- 19:31Speaker 1: And for the heavy lifting.
- 19:32Speaker 2: Finally, when the architecture demands robust, offline capable applications processing
- 19:37Speaker 2: massive data sets without freezing the user interface, you invest
- 19:40Speaker 2: the time to learn index dB.
- 19:42Speaker 1: Mastering these tools is the dividing line between a web
- 19:45Speaker 1: page that feels clunky and fragile and a modern web
- 19:48Speaker 1: application that feels lightning fast and actually respects the user's
- 19:51Speaker 1: data plan. We finally have the medicine to cure the
- 19:54Speaker 1: browser's amnesia.
- 19:55Speaker 2: We do, and you know it prompts a rather profound
- 19:57Speaker 2: reevaluation of the modern technology staff. Well Browsers have evolved
- 20:02Speaker 2: from simple document viewers that forget everything the moment you
- 20:05Speaker 2: close the window into massive localized databases capable of executing
- 20:10Speaker 2: complex business logic entirely.
- 20:12Speaker 1: Offline, which fundamentally challenges the dominance of the cloud.
- 20:16Speaker 2: It really does. If the application logic, the interface rendering,
- 20:20Speaker 2: and the primary data storage all live entirely on your
- 20:23Speaker 2: laptop or your phone, the server is no longer the
- 20:26Speaker 2: main character in the transaction. Wow, we are approaching a
- 20:30Speaker 2: threshold where your local device becomes the ultimate source of
- 20:33Speaker 2: truth and the Internet is reduced to nothing more than
- 20:36Speaker 2: a synchronization cable to a cloud backup.
- 20:38Speaker 1: That is wild to think about. Imagine going back to
- 20:41Speaker 1: that friend's house tomorrow. You knock on the door, they
- 20:43Speaker 1: open it, and not only do they know your name instantly,
- 20:45Speaker 1: but they have your favorite coffee already pour, your favorite
- 20:47Speaker 1: music playing in a meticulously organized filing cabinet containing every
- 20:52Speaker 1: conversation you've ever had.
- 20:53Speaker 2: A profound shift from amnesia to instantaneous local recall
- 20:59Speaker 1: The Browsermit, go build something that doesn't forget