Cloudflare announces 'Durable Objects' for 'stateful serverless'

Cloudflare's serverless computing service, Cloudflare Workers, has announced a new feature, Durable Objects , that preserves the state of code running on the service and enables stateful services. By using Durable Objects, you can ensure data consistency that was difficult to achieve with serverless computing, and you can also realize real-time processing between multiple clients.

Workers Durable Objects Beta: A New Approach to Stateful Serverless

Cloudflare Workers is a service that allows you to execute code such as JavaScript on the edge (Worker) of a content delivery network (CDN) that caches websites on DNS servers around the world and optimizes communication to clients. It is a serverless structure service that allows users to execute code without preparing a server .

Cloudflare Workers, which has a serverless structure that distributes processing to the edge, is very convenient because it does not require server management and can optimize processing according to the physical location of the client, but Building a 'stateful' service that preserves code state and flexibly changes processing is difficult with Cloudflare Workers because it requires data consistency across edges and coordination across multiple clients. It was said that. 'Durable Objects' solves this problem, making it easy to build stateful services such as game services and shopping sites that were previously difficult to achieve with Cloudflare Workers.

Durable Objects makes it possible to build stateful services even in a serverless structure by persisting the state of objects in the code. The object is connected to storage to hold its state and is given a unique identifier. Edges operating around the world access objects based on identifiers to maintain consistency between edges and coordination among multiple clients.

When using a normal cloud service, select a 'region' that represents the area of the data center as close as possible to the physical distance to the client, but the data center where objects are placed in Durable Objects depends on the situation on the Cloudflare side. The region is 'Earth' because it is automatically selected.

Multiple clients interact with each other through a 'coordinator' generated by Cloudflare. The coordinator is in charge of asynchronous processing that resolves processing conflicts between clients, stacks processing, and reflects it later. With the official release of Durable Objects, Workers will support the

WebSocket protocol, which will facilitate real-time processing between clients.

A demo of the chat app implemented in Durable Objects and WebScoket is available, and you can try it from the URL below.

You can chat anonymously when you enter the chat room. The object in this demo is a 'chat room', and the 'chat content' that is the state of the object is made persistent by Durable Objects.

Traditionally, serverless is compatible with stateless services, and it has been difficult to build stateful services. In order to connect serverless and stateful, it is necessary to divide the state into small pieces, just as serverless first divided the computing into small pieces. The unit for dividing a state varies depending on the application. For example, a chat room is used for chatting, and a shopping cart is used for online stores. Durable Objects is a service with excellent scalability by using the division unit of the state as an object and linking the object with the storage for persistence on a one-to-one basis.

Durable Objects is in beta at the time of article creation, and you can request an invitation to beta from the URL below.

Cloudflare Workers® Durable Objects Limited Beta Program | Cloudflare

in Web Service, Posted by darkhorse_log