Making The Earth App: A Hybrid Backend

hybrid backendbackendcloudmantle2crust
Making The Earth App: A Hybrid Backend
3 min. read

This is the beginning of a series where I detail how I made and designed The Earth App, and what I learned along the way.

Part 1: A Hybrid Backend

I coined the term "hybrid backend" to describe a backend that uses two fundamentally different languages or frameworks, in separate codebases, that communicate with each other to form the entire backend service. The Earth App uses a hybrid backend in this instance. It uses Drupal/PHP as the primary API server, exposing public endpoints that the frontend uses, and a secondary API powered by serverless Cloudflare Workers with TypeScript.

The Differences Between the Two

This table should capture most of it:

mantle2 cloud
Languages/Framework Drupal, PHP CF Workers, TypeScript
Purpose Public API Endpoints Private Internal Operations
Role Primary Secondary
Authentication None (Anonymous), Account Tokens/Password Internal Token
Works with Redis, Symfony, PostgreSQL Cloudflare AI, R2, KV, Images

The purpose of cloud is to handle serverless operations that would be better suited on a Cloudflare serverless network, like AI generation and image optimization. Everything else is handled on a dedicated VPS with mantle2, hosted on Drupal.

Drupal was chosen because it works well for the use case of The Earth App when it comes to users and content management, and because my original solution was too slow. The original solution and cloud both used cloudflare workers, but cloud was never switched to a different base altogether.

Communication Workflow

Between the frontend (aka crust), mantle2, and cloud, they all communicate with each other in a triangle.

crust <-> mantle2

crust will send requests to mantle2 for normal content information (users, prompts, articles, etc.). mantle2 stores all of the content within a PostgreSQL database, wrapped around a Drupal content type with fields. mantle2 usually responds with JSON information.

crust <-> cloud

Some administrator operations directly link to cloud, such as the generation of activities or cleanup of the R2 blob storage. In addition, journies are stored in Cloudflare KV and not Redis, so crust communicates with cloud to retrieve your journey data.

In addition, the @earth-app/ocean NPM package, which is installed on both crust and cloud via Kotlin/JS, facilitates recommendation algorithms on both sides. crust will usually send data retrieved from mantle2, send it to cloud, and use either the package's recommendation algorithm or a text classification model from CF AI that ranks specified data.

mantle2 <-> cloud

cloud sends the majority of data to mantle2 though various AI output for activities, articles, or prompts. It uses ocean as well, which retrieves scientific papers for the article output.

The only current use case of mantle2 sending data to cloud is when mantle2 forwards the profile photo endpoints directly to cloud.

Conclusion

This wraps up a summary detailing the hybrid backend. More information to come on specifics about each component of The Earth App. You can kind of guess what each component does based on its name.

Post by The Earth App | Last updated: November 29, 2025
Copyright © 2025 NuxtPress. All Rights Reserved.