The infrastructure and DNS service provider Cloudflare has announced expanded database functions for its serverless platform Cloudflare Workers, which is tailored to developers. The company is now making its durable objects generally available and announcing new database connectors for TCP connections as well as partnerships with MongoDB and Prisma.
More storage options for application development
With the Durable Objects announced as beta last year, Cloudflare expanded its worker-edge computing platform to include the option of coordinating state management across workers without having to resort to a classic database. In addition to the data storage devices Workers KV and R2 (S3-compatible object storage), developers were given the option of implementing stateful applications such as collaborative whiteboards or game servers with just a few lines of code.
In contrast to databases, Easily configure durable objects for the special requirements of workers. Problems caused by the extensive concurrency or too frequent transaction rollbacks due to the coordination of shared keys should be avoided by using the durable objects. The function is now generally available and released for productive use.
Cloudflare is working on a new API, especially with regard to the connection of classic relational databases, to make the TCP-, UDP- and QUIC-based protocols accessible. So far, developers have been limited to http and WebSocket connections when using the Cloudflare Workers.
Via tunnel into the relational database
In the first step, Cloudflare now enables access to relational databases such as Postgres and MySQL by setting up and managing a tunnel via
cloudflared. The procedure allows a connection from http to TCP via WebSockets. The approach shown in the figure below can be using a Postgres example.
The concept still requires the implementation of the tunnel on the users’ infrastructure. The company plans to add database connection management hosted by Cloudflare in future releases and then also provide native support for TCP in the form of the planned socket workers.
Until then, developers have the alternative option of creating their desired database beyond the existing integrations with Macrometa and Fauna about new ones like MongoDB Atlas and Prisma in the Cloudflare Workers. As an ORM (Object-Relational Mapper), Prisma can be used, for example, to convert database entries into code and integrate them into Cloudflare Workers via the Prisma Data Proxy. The Prisma Client works with the Postgres, MySQL, SQL Server, SQLite and MongoDB databases.