A multi-player web app needs a backend, right?
What if I told you, it doesn’t?
Read on for how Croquet gets rid of servers. No, really.
Instantaneous Shared Experiences is how we describe Croquet on our website. And while that excellently describes What Croquet does, as Croquet's Chief Architect, I wanted to share a bit about How we do that.
So I wrote a Twitter thread. Here it is in blog form, slightly extended.
Croquet lets you build completely client-side multi-user web apps.
Read that again.
No I’m not kidding. I built it, I know it works. 😁
Croquet apps run completely client-side:
- can be hosted as a static web site
- no server-side code needed
- no networking code needed
Croquet is literally virtualizing the server: Instead of running code on a server (or in a serverless function) we run it as a virtual machine (VM) on each client.
Croquet carefully controls the inputs to these identical VMs so they execute in sync.
The input events for the shared VMs are routed via Croquet’s global fleet of “reflector” servers. A reflector just bounces events from one user to all users. There’s no computation involved. Reflectors are small and fast. We have them around the globe, and will have many more with extremely low latency soon.
Crucially, the reflector guarantees event order and timing so every VM processes the same event at the same time. (That’s what the animation on top shows.)
Croquet reflectors also send out a continuous heartbeat to keep the VMs running, and in sync, without user input.
Since the “server” is really a VM running on the client, you get unlimited bandwidth from that “server” to the client.
In fact, you can directly “reach into” the replicated VM to pull out any data for rendering. It’s just a pointer 🤷🏻♀️
Croquet also snapshots these VMs, encrypts the snapshots, and uploads them to a server until the next time they are needed.
The encryption key never leaves the client. Our servers cannot peek into the snapshots. They can’t peek into events either, since those are fully end-to-end encrypted, too.
And yes this really works. In a web browser. In your browser, in fact. Try this:
That’s WideWideWorld, an editable voxel world with hundreds of AIs running around, and a water simulation. Scan the QR code in the lower left with your phone (or share the session URL). Both clients will be in sync.
Of course, to build something like WideWideWorld on top of Croquet you’ll need to know how to build a game in the first place. This prototype is by our own Brian Upton (whom you might recognize from Rainbow Six & Ghost Recon). He joined us because no other tech would allow him to build this.
Croquet is especially good for:
- multi-user AR / VR / WebXR
- multi-player games
- collaborative design and construction
- synchronized media
- shared simulations
- quick prototyping of shared experiences
These are hard to build, and some of the really hard parts are always the networking and server design, implementation, deployment, and scaling.
Croquet eliminates this headache.
By the way, we are not literally running a Docker image in the browser. Although that would be a fun exercise – theoretically, Croquet can run anything that is deterministic and serializable.
Plus our API is much simpler than traditional client/server code. Your shared server “VM” can be a single class, and you interact with it simply using publish/subscribe!
The value of n will be synchronized between all VMs
even as it is incrementing automatically.
We have many simple tutorials to get you started:
(also: hiring a #DevRel engineer to write more)
We are working on higher-level frameworks, too:
- Yoshiki Ohshima’s Croquet Virtual DOM (which even allows #livecoding)
- Brian Upton’s Croquet WorldCore (the Game Engine behind W3 we demoed at GDC)
VDOM is already available, and WorldCore soon! See croquet.io/docs
By the way, if you heard of Croquet about 15 years ago – yes, that was us too, in particular our founder David Smith working with Alan Kay.
That system was written in Squeak Smalltalk and had a fancy 3D UI.
Our new JS system has no UI, so it's good for many kinds of apps.
Croquet provides this missing infrastructure for the web.
Try it! No servers needed.
(if you 💜 servers come work with us though)
Compiled from a Twitter Thread I posted the day after Croquet's public launch.