IPFS - The Theory
Let's start with something easy. Suppose we have a fantastic website, like the one you are looking at right now (because yes, it is clearly very well made, thank you). It is hosted by a server: Apache, Nginx, Lighttpd, whatever you prefer. Serious stuff.
Now something bad happens: the server becomes unreachable. Why?
- It crashes.
- They block it.
- They seize it.
- It explodes (it happens, especially on Friday nights).
If the server isn't there, the website isn't there. The end. Grave silence. A shame, because it was really a nice website.
How could we solve this horrible thing?
Let's do a little mental game.
Imagine the server is up, and one of you – let's call them First Visitor – opens the site. A copy remains in their cache. Nothing strange: it happens even now.
But what if that copy wasn't just for them? What if anyone else could fetch the site not just from the main server, but also from the First Visitor's computer?
Then a Second Visitor arrives. They download the site from the main server and also from the First Visitor. And they keep a copy too.
Then a Third Visitor arrives. They can download the site from:
- The main server
- The First Visitor
- The Second Visitor
And so on, like an avalanche.
At this point, it no longer matters if the official server goes offline: the site is already scattered around in people's caches. New visitors get it from those who already have it. The site no longer dies.
What is IPFS (without intellectual masturbation)
IPFS stands for InterPlanetary File System. The name is intentionally exaggerated. But the concept is simple: it's a peer-to-peer network of computers passing files to each other, without the need for a central server.
It is not "a server giving files to many clients". It's many clients giving files to each other.
It works more or less like this:
- I create an IPFS node.
- I add a file, for example,
index.html. - IPFS calculates a CID (Content Identifier). It looks like something like
/ipfs/QmeAYko7TLNHpN5a7vSvgJoTD7J1RCNdBunMzNcabuPTvp. - My node tells the network: "Hey guys, I have the file with this CID here."
and theeeen:
- First visitor wants that file. They ask the network: "Who has the file with CID QmeAYko7TLNHp...?"
- The network replies: "Tizio has it over there, at IP address X."
- The visitor downloads it and keeps a copy.
and theeeen:
- Second visitor asks for the same CID. The network says: "Tizio has it, AND so does the first visitor."
- The second downloads from whoever is closer/faster/available. They keep a copy too.
and theeeen:
- Third visitor has even more sources.
and theeeen:
...and you get the point, that's enough, just like in the mental game from before.
The catch with the long-haired, pretty-horned beast: if you change the file, everything changes
Now comes the part that makes you swear (just a bit, though, it gets resolved).
Suppose I modify my beautiful index.html. Maybe I add a comma. Or a photo of a potato, the SI unit of measurement.
On the normal web: I overwrite the file on the server, and goodbye.
In IPFS: the file is different → its CID becomes completely new.
So I add the new index.html and tell the network: "Hey guys, now I also have the file with the new CID Qmc7hm9rBs3wsR52uzLR9RABu..."
But the old CID still exists in the caches of those who visited it before. So now there are two versions of my site. An old one, a new one. Both accessible. Both immutable. Both BEAUTIFUL, but one also has a potato.
And if tomorrow I make another edit → another new CID.
And another one → another new CID.
Every modification = a new address.
Now, the question arises naturally: wait, do I have to tell everyone the new address every single time?
IPNS: The trick to never change links
There is a wonderful thing called IPNS (InterPlanetary Name System).
It works like this:
I generate a private key (my own, personal, untouchable) and from it I derive an IPNS address. It looks like something like
/ipns/k51qzi5uqu5...This address will never change. Ever.What do I do with it? I tell IPNS: "Hey, point to the latest CID I published."
Today:
/ipns/k51qzi5uqu5... → /ipfs/QmeAYko... (version 1 of the site)Tomorrow I update the site → I get a new CID. I republish to IPNS:
/ipns/k51qzi5uqu5... → /ipfs/Qmc7hm9r... (version 2 of the site)The IPNS address stays the same. What changes is the target.
Result: I can give everyone just one address (/ipns/stuff...) which always points to the latest version of my site, without having to re-share anything.
A small side note
The copies that end up on users' computers do not stay there forever. Every now and then, the garbage collector comes and cleans them up, because you can't go filling everyone's disks with other people's crap. Unless a user decides to PIN the CID.
It means: "Do not delete this content. I want to keep it on my disk forever (or until I remove it)." Pinning a site means voluntarily becoming one of the servers for that site.
Bonus Track
A warning.
If you put something on IPFS, you accept that it could potentially stay alive forever. If someone pins your content, they will have a copy and can redistribute it at will. Just as others cannot censor you, you cannot censor yourself either. You have no right to be forgotten.
[May the talpone be with you]
[EOF]
Discussion and support channel. To discuss configurations or other topics, join us on fluxer.dreadful.work.

