DEV Community

Andres Correa
Andres Correa

Posted on

Ever Wondered What Really Happens When You Hit "Save"? 📝

You’re writing code in VS Code, tweaking configs, or jotting notes in a markdown file. You smash Ctrl+S (or Cmd+S 🍏)... and magically, your data is “saved.” But what’s actually going on under the hood?

It turns out, that simple action kicks off a fascinating journey, from fast, volatile RAM to your trusty hard drive or SSD. Let’s follow the data’s path 👇


Part 1: The home of your data 🏡

Old-School Spinning Disks 🎡

Imagine a vinyl record player, but instead of playing music, it stores your data. That’s basically a Hard Disk Drive (HDD).

  • Inside, you’ve got metallic platters coated with tiny magnetic regions called domains.
  • Each domain can “point” north or south, representing a binary 1 or 0.
  • Writing data = flipping those directions.
  • Reading data = detecting the orientation with clever sensors.

This is of course an oversimplification, but the idea still holds.


Solid-State Drives ⚡

Now, let’s level up. SSDs don’t bother with moving parts, they trap electrons in tiny cells called Charge Trap Memory.

  • A cell’s charge level = different bit values.
  • SLC: 1 bit per cell (fast, durable, \$\$\$)
  • MLC: 2 bits per cell
  • TLC: 3 bits per cell
  • QLC: 4 bits per cell (dense, cheap, but slower)

Picture a giant spreadsheet:

  • Cells = individual memory cells
  • Rows = pages
  • Stacks of spreadsheets = blocks

That’s how SSDs structure your data. Super compact, but it comes with trade-offs in performance and durability.


Part 2: How Filesystems Play Traffic Cop 🚦

Here’s where it gets fun. Your data isn’t usually stored neatly in one place (sorry, perfectionists 😅). It’s scattered in chunks across the disk.

So how does your OS keep track?

  • The disk uses LBA (Logical Block Addressing) to divide space into addressable chunks.
  • The Filesystem (NTFS for Windows, ext4 for Linux, APFS for macOS) maps file paths ➝ metadata ➝ LBAs.

👉 Example: You open resume.pdf

  1. OS hands the path to the filesystem.
  2. Filesystem uses the path as an index and looks up the file’s metadata.
  3. Metadata lists which LBAs belong to resume.pdf.
  4. Disk controller fetches those blocks.
  5. Boom! your file appears in your editor.

💡 Writing works the same, but in reverse: filesystem decides where new chunks go, disk stores them, controller signals success, OS says “all good!”


Why Should You Care? 🤔

  • Performance: Understanding SSD vs HDD trade-offs helps when designing databases or logging systems.
  • Reliability: File corruption bugs often come from misunderstanding how writes really work.
  • Optimization: Filesystem choices (ext4 vs XFS vs ZFS) matter for servers and cloud deployments.

✨ Next time you hit Ctrl+S, remember: behind that instant “save” is a beautiful orchestra of magnetism, electrons, and metadata making it all possible.

Top comments (0)