How to use IPFS to store application state (as a backend for dApp)?
Asked Answered
J

1

6

I am just starting with IPFS and Ethereum. We are building a dApp (mobile) and planning to replace the standard API & DB layer with IPFS and Ethereum. So, after lots of reading I have the following questions,

  1. Making dApp directly talk to IPFS (via IPFS APIs) to store data (app. data or files) and fetch data. ie, completely replacing the API layer with IPFS seems possible, but is there any issue with this approach? can we live without APIs at all?

  2. If point 1 is possible, accessing the file data is straight forward but how to access the app. data in IPFS (e.g: what is the recommended structure to store and retrieve, how to store different user data etc)?

  3. I understand that the data added to IPFS is available publicly, how can we protect that data and make it available only for the specific client? As I understand that there is no public/private key mechanism in IPFS?

  4. When we store videos in IPFS, to stream the video in the client, do we need to use CDNs and I am not sure how to do that in a decentralised solution.

  5. Is there any option available in IPFS to perform a task (e.g.: running a script) automatically when some events are triggered or upon commanded by the client apps?

  6. Is there any known performance issues with IPFS when finding and fetching the data from a node?

  7. Any suggestion on the tools and frameworks available to achieve the above approach?

Thanks in advance.

Jennifer answered 30/10, 2018 at 17:33 Comment(0)
C
4

Making dApp directly talk to IPFS (via IPFS APIs) to store data (app. data or files) and fetch data. ie, completely replacing the API layer with IPFS seems possible, but is there any issue with this approach? can we live without APIs at all?

Depends on what you want to do. But with content-addressed storage, IPNS, and ipfs pubsub you have all components to write some very complex applications that do not use any centralised service.

Especially pubsub is still experimental. But the latest version of IPFS, 0.4.18, contains a new pubsub implementation that should be much more scalable.

If point 1 is possible, accessing the file data is straight forward but how to access the app. data in IPFS (e.g: what is the recommended structure to store and retrieve, how to store different user data etc)?

You just publish your app under an IPNS key that you control. Assuming we are talking about javascript/typescript apps here, you can package them just like you would usually do, using tools like webpack, and the put the final artefact on IPFS and publish using IPNS.

I understand that the data added to IPFS is available publicly, how can we protect that data and make it available only for the specific client? As I understand that there is no public/private key mechanism in IPFS?

Each IPFS node has a public/private key pair. You can use that to encrypt messages for a node or to sign messages from a node. This is used in IPNS. You can have more than one keypair per node.

When we store videos in IPFS, to stream the video in the client, do we need to use CDNs and I am not sure how to do that in a decentralised solution.

IPFS basically is a CDN. So you would not have to use an extra CDN. You could also use the Cloudflare IPFS gateway.

Work to make IPFS very efficient for distribution of very large files such as videos is currently ongoing. There are apps already using this, such as D.Tube

Is there any option available in IPFS to perform a task (e.g.: running a script) automatically when some events are triggered or upon commanded by the client apps?

No. IPFS/libp2p is basically the network stack for the distributed web. If you want functionality such as automatic execution of scripts triggered by events, you would either have to write it yourself on top of IPFS pubsub, or use more high level middleware such as Orbit DB.

Is there any known performance issues with IPFS when finding and fetching the data from a node?

Yes. IPFS is still pretty young. E.g. there is an issue with the distribution of large files from many peers that is currently being worked on. Many companies are using IPFS in production, but you will be living on the bleeding edge and have occasional issues.

Any suggestion on the tools and frameworks available to achieve the above approach?

Difficult to answer without knowledge of the overall goal and the skill level of the developers. If you want maximum performance, you will have to use IPFS or libp2p directly. To get started, it might make sense to build on something like OrbitDB.

There are also lots of examples for JS-IPFS to get started.

Charest answered 12/11, 2018 at 17:53 Comment(4)
Thanks for the answers. With app. data, I mean the app. state data (like user related data and other logical data required to run the app.). So, I am actually looking for a proper way to store the app. data in IPFS and retrieve that effectively.Jennifer
If we encrypt the messages using a specific node, we have to let the client to speak only to that node, which is not in our control since there can be multple nodes which has the same data and the nearest client will serve the data to the client?Jennifer
Is there any way or tools available to test the IPFS performance in storing and fetching the data by simulating n number of nodes on the fly?Jennifer
It is perfectly possible to put app data on the local IPFS (js-ipfs, directly running in the browser). But if it is user specific data you would have to encrypt it. Then when you have multiple devices you have the problem of getting the secret from one device to another. Options are username/password as well as producing / scanning a QR code or bumping the devices and using NFC. Maybe ask a separate SO question for how to transfer secrets? IPFS has some internal benchmarking tools that allow them to spin up a large number of nodes on a single machine and simulate various scenarios.Wester

© 2022 - 2024 — McMap. All rights reserved.