Introduction to Mycelial
Build local-first, distributed, decentralized applications
local-first, distributed, decentralized applications mean?
Up until recently, you had two options when creating an application:
- Local applications and
- Client/server applications
Each of these types of applications has its strengths (and weaknesses). For example, local apps are typically fast because they don't need to talk to servers over slow networks. However, if your app needs multiple users to collaborate on common tasks, then a local application won't work for you; you'll probably need to create a client/server application, right? Well, maybe, but now a third option allows you to combine many of the best features from local and client/server applications. It's a new, best-of-both-worlds paradigm.
How it works
Imagine you wanted to build a basic contacts application that you can share with the people in your household.
Ideally, anyone in your house should be able to create, update and delete shared contacts. You might be inclined to make this a typical client/server application, but you're not restricted to client/server anymore because of a recent innovation called Conflict-free Replicated Data Types (CRDTs).
What are Conflict-free Replicated Data Types (CRDTs)
CRDTs are a collection of data types similar to other data types you're probably familiar with, such as Arrays, Maps, and Sets.
The interesting thing about CRDTs is that any local changes you make to a CRDT can be copied and merged into a replica on a different computer without any conflicts. So, for example, in your contacts application, you could add, update and delete some of our shared contacts, and the changes you make are guaranteed to replicate and merge with my contacts without conflict. Even if we both make edits to the same contact, at the same time, there are mechanisms to synchronize our changes in a conflict-free way.
How to synchronize changes
CRDTs are transport agnostic, meaning you can use any method to send updates from one replica to another. For example, you could use WebSockets, Bluetooth, or even sneakernet. However, peer-to-peer options such as WebRTC are usually preferred.
A local first application means everything your application needs to function is co-located with the application; in other words, all the logic and data required to run your application is on your computing device. This means your application runs fast, and it works when offline, so for example, if your car gets a flat in a rural area with no data coverage, you can still access your contacts and call for help.
Your contacts application is distributed because it doesn't just live on one device; it lives on every device in your household.
Because there is no single source of truth, ie no central server, your contacts application is decentralized.
Learn more about CRDTs
You don't need to know exactly how CRDTs work to use them; you just need to know how to use our APIs. But if you're interested in learning more about CRDTS, you can checkout crdt.tech] or watch our introductory video.