Building globally distributed apps with Cloudflare and Fauna

This self-paced workshop will demonstrate building a globally distributed application using Cloudflare and Fauna, deployed in multiple geographic regions. Our application will be a minimalist version of a video-sharing application, mimicking the popular apps Loom or Dropbox Capture. To do so, this workshop will guide you through the following topics:

  1. Build and deploy a Next.js application with Cloudflare Pages, hosted on Cloudflare’s global edge network.
  2. Demonstrate Fauna's capability as a globally distributed database and how it enables quick data access from any location.
  3. Deploy serverless backend code with Cloudflare Workers across the globe to give it exceptional performance, reliability, and scale.
  4. Show how CloudFlare’s R2 global object storage can deliver files to applications with minimal latency.

Once you have a working application, we’ll finally review some best practices that we’ve seen from other customers as they deploy and improve full-stack, serverless edge applications.

Preview the final demo application here.

Get the complete code for this project here.

The only prerequisites to complete this workshop are some experience with JavaScript or TypeScript, and one of the widely-used standard web frameworks like Node, React, or Next.js.

Why Fauna and Cloudflare

You may be wondering why you should choose to build your application with this particular stack of tools. There are a numbers of reasons which all come down to the fact that this technology stack is well suited for quickly building scalable applications by:

  1. Taking advantage of serverless computing to build and scale applications fast.
  2. Delivering a low-latency user experience to all of your customers across different global locations.
  3. Dedicating more engineering time and resources to deliver features rather than spending time figuring out how to scale and manage application and database servers, which arguably is undifferentiated work.

Why use Cloudflare Workers/Pages function

By default, Workers and Pages Functions are invoked in a data center closest to where the request was received. If you are running back-end logic in a Worker, it may be more performant to run that Worker closer to your back-end infrastructure rather than the end user. Smart Placement automatically places your workloads in an optimal location that minimizes latency and speeds up your applications.

You may benefit from Smart Placement if you are making multiple round trips to a centralized database, API or origin server in a Worker.

Why Fauna

Fauna is a distributed relational database with a document data model delivered as a cloud API. It offers advanced querying capabilities, robust consistency guarantees, and comprehensive support for data operations. It automatically replicates your data in multiple locations worldwide. This means that when a user requests your app, the data can be fetched from the nearest geographic copy, reducing the time it takes to retrieve the data and send it back to the user.

Similar to Cloudflare’s smart placement Fauna uses intelligent request routing, which fetches or writes data to the nearest replica without developers having to specify which replica to use.

Why Cloudflare R2

Cloudflare R2 Storage allows you to store your unstructured data (blob) nearest to your customers, reducing latency.There are no egress fees in R2, which can unlock some very neat use cases.

Application Architecture

Getting Started

Implementing Video Recording

User Authentication

Data Relationship

Putting it all together

Last updated on August 17, 2023