About

Wednesday, October 21, 2020

“Durable”

Looks like the word “durable” is an emerging term in the world of serverless. As I understand it, it’s like allowing for state in places you wouldn’t normally expect to have it. For example, you call some cloud function and run some JavaScript… unless you have it go get some data from elsewhere, it has no information other than it’s own code. It doesn’t remember what happened last time it ran. It’s a clean slate each time. But let’s say your cloud function was a class, and when you initialized that class you got an ID, and through that ID you could talk to that exact instance of that class whenever you wanted. That instance sticks around as long as you need it. It’s durable.

Android Chrome Android Firefox Android Browser iOS Safari Opera Mini
No No No No No

Cloudflare released a feature called Durable Objects:

… we settled on “Unique Durable Objects”, or “Durable Objects” for short. Let me explain what they are by breaking that down:

Objects: Durable Objects are objects in the sense of Object-Oriented Programming. A Durable Object is an instance of a class — literally, a class definition written in JavaScript (or your language of choice). The class has methods which define its public interface. An object is an instance of this class, combining the code with some private state.

Unique: Each object has a globally-unique identifier. That object exists in only one location in the whole world at a time. Any Worker running anywhere in the world that knows the object’s ID can send messages to it. All those messages end up delivered to the same place.

Durable: Unlike a normal object in JavaScript, Durable Objects can have persistent state stored on disk. Each object’s durable state is private to it, which means not only that access to storage is fast, but the object can even safely maintain a consistent copy of the state in memory and operate on it with zero latency. The in-memory object will be shut down when idle and recreated later on-demand.

Pretty cool. The real-time aspects are extremely compelling.

Azure is also using “durable” in their offices through Durable Functions. Part of that offering is Entity Functions:

Entities behave a bit like tiny services that communicate via messages. Each entity has a unique identity and an internal state (if it exists). Like services or objects, entities perform operations when prompted to do so. When an operation executes, it might update the internal state of the entity. It might also call external services and wait for a response. Entities communicate with other entities, orchestrations, and clients by using messages that are implicitly sent via reliable queues.

The documentation is a little tricker for me to understand (I think it’s aimed at people who live and breath this stuff more than I do), but the concept sounds very similar to Cloudflare’s thing. Entities have IDs that you access them through. They persist and can be used for the same real-time-y stuff, like displaying the state/score of a video game to anyone who is connected.


The post “Durable” appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.



source https://css-tricks.com/durable/

No comments:

Post a Comment