Introduction to IPFS

Introduction to IPFS

Symphony Logo
Symphony
January 16th, 2023

Today’s web is great, we use it all the time every day. But it might have some issues as well:

  • Today's web can't preserve humanity's history. A website's average lifespan is around 2 years and 7 months before it’s gone forever
  • Today’s web is getting centralized and dependent on the backbone, where more and more of the internet is hosted in the big cloud providers, which might impact internet resilience. In other words, for today’s web to work you need to be connected
  • Today’s web is based on location addressing (DNS) where it fetches content by the location, not giving tools to validate it’s authenticity and history, allowing possible censorship and manipulation
  • Today’s web is also inefficient, bloated with ads and trackers. Peer-to-peer technology has existed for a long time but it’s not used to distribute high volumes of data

Is there any possible alternative?

IPFS

InterPlanetary File System (IPFS) is a protocol, hypermedia, and file sharing peer-to-peer network for storing and sharing data in a distributed file system. IPFS uses content-addressing to uniquely identify each file in a global namespace connecting IPFS hosts.

IPS tries to solve the mentioned problems since it is decentralized by being P2P, allowing resilience and making it harder to censor content. It can also speed up the web when you're far away or disconnected. It also uses content addressing, storing data by its content and not by its location.

How does it work?

When you add a file to IPFS, your file is split into smaller chunks, cryptographically hashed, and given a unique fingerprint called a content identifier (CID). This CID acts as a permanent record of your file as it exists at that point in time.

When other nodes look up your file, they ask their peer nodes who's storing the content referenced by the file's CID. When they view or download your file, they cache a copy — and become another provider of your content until their cache is cleared.

screenshot-2023-01-17-at-123920-4

A node can pin content in order to keep (and provide) it forever, or discard content it hasn't used in a while to save space. This means each node in the network stores only content it is interested in, plus some indexing information that helps figure out which node is storing what.

If you add a new version of your file to IPFS, its cryptographic hash is different, and so it gets a new CID. This means files stored on IPFS are resistant to tampering and censorship — any changes to a file don't overwrite the original, and common chunks across files can be reused in order to minimize storage costs.

However, this doesn't mean you need to remember a long string of CIDs — IPFS can find the latest version of your file using the IPNS decentralized naming system, and DNSLink can be used to map CIDs to human-readable DNS names.

IPFS deployment seeks to include native support of IPFS in all popular browsers and tools. Gateways provide workarounds for applications that do not yet support IPFS natively. The main public gateway is ipfs.io, but there are third-party gateways which you can check here.

How to try it out?

IFS is available as a desktop application or CLI. IPFS is also available as a JS SDK or Go SDK.

To quickly try it out just install the CLI, and run to initialize the IFPS repository. ipfs init

To run the IPFS node. ipfs dameon

Now you can add any file to the IPFS network, for example create a text file and upload it. ipfs add HelloWorld.txt

You will get a hash, a Content Identifier (CID). You can fetch it by doing the following. ipfs cat {CID}

You can also download it on your browser by using the public gateway.

As mentioned above, each CID is immutable, so what happens if we change the content of the file? As expected, it will generate a new CID because the content is different.

In order to publish the file under IPNS do the following. ipfs name publish /ipfs/{CID}

The output is a public key of that IPNS name. You can download the file on your browser by using the public gateway but with ipns prefix https://ipfs.io/ipns/{KEY}

Now you can change the content and republish it again. ipfs name publish {KEY}

In order to see which is the CID of an IPNS key do use the following. Ipfs name resolve

If you would like to not run the IPFS node, there are several online gateways that can host the files for you like Infura or Pinata.

Where is IPFS used?

IPFS is now supported in Brave browser allowing you to run your own IPFS node in-browser.

IPFS is mostly used for blockchain development as its content addressing enables you to store large files off-chain and put immutable, permanent links in transactions — timestamping and securing content without having to put the data itself on-chain.

IPFS is a great tool to host static websites (and even non-static) in a decentralized and distributed way. You can try it out using Fleek. Several web3 blogs are hosted on IPFS, for example.

IPFS can also be used to create decentralized apps since any type of data can be distributed, including code. When you access the application, it is downloaded into your node, becoming available for distribution and the copy is always available unless deleted.

Is it a clear solution?

IPFS relies on a distributed network, which means if the last node holding a content is down, the content is simply not available. Public gateways are not hosting services and will delete content if it’s not constantly fetched. Ultimately, in order to keep content alive, you have to host your own IPFS node. Distributed network also means the file sharing might be slow in the beginning until the file is distributed to more nodes although you can configure which gateways your node will ping in order to be accessible faster.

Content immutability is an issue if the content changes frequently. IPNS is the best solution but it requires another layer of complexity and storage for key management. This is the reason why most public gateways don’t provide IPFS support. DNSLink is mostly useful for static content, like a landing page for a web site, for example.

Last but not least, non-web 3.0 projects using IPFS are mostly in beta version or academic attempts to show the potential of the protocol. Like any distributed system, it needs to be widely used to demonstrate its power. When it comes to web3, IPFS is a go to protocol, going hand to hand with blockchain smart contracts and NFTs.

How to learn more?

IPFS documentation is the best introduction. You can also check the online interactive course in Protoschool.

Resources

About the author

Tiago Knoch is a Solution Architect with 10+ years of experience working at our engineering hub in Novi Sad.

Tiago is a Solution Architect who utilizes a diverse tech stack while working on desktop and web applications for various clients, including world industry leaders. He is a certified Azure Cloud Architect and a certified Scrum Master. Keeping up with the latest technologies and industry trends, he works hard on developing and using his development skills in alignment with industry requirements and trends.

Contact us if you have any questions about our company or products.

We will try to provide an answer within a few days.