proomt

Search

Search posts, papers, and topics

All posts

SitePoint17 min readtutorialintermediate

Building ASGI Microservices with Cloudflare Python Workers in Production

Summary

Step‑by‑step tutorial for deploying a FastAPI‑based ASGI microservice on Cloudflare Python Workers, covering the Pyodide runtime limits, ASGI bridge, Wrangler setup, pure‑Python dependency handling, KV caching, and a concrete BFF aggregation example.

  • Cloudflare Python Workers run CPython compiled to WebAssembly (Pyodide) – no filesystem, no subprocesses, and no native C extensions unless pre‑compiled by Pyodide.
  • The platform provides a built‑in ASGI bridge: a `fetch` event is translated to ASGI `scope`, `receive`, and `send` callables, eliminating the need for adapters like Mangum.
  • Use `wrangler` to scaffold a Python worker, configure KV bindings, environment vars, and a build command that forces pure‑Python mode for packages like Pydantic (`PYDANTIC_PURE_PYTHON=1`).
  • Prefer pure‑Python, async‑compatible libraries (`httpx` over `requests`, `fastapi`, `pydantic` in pure‑Python mode) because Pyodide cannot load most compiled wheels.

Running ASGI apps at the edge reduces client‑to‑origin latency (p50 ≈ 50 ms vs 200 ms) and enables per‑region aggregation, but the edge runtime imposes strict constraints on dependencies and state. Understanding these limits and the required tooling (Pyodide, Wrangler, KV) is essential for building…

6/10

Related reading

  1. Python Workers are now generally available

    Python Workers are now GA on Cloudflare Workers. The runtime uses Pyodide‑compiled WebAssembly to run Python, adds first‑class support for Cloudflare bindings (queues, KV, etc.) without manual JS conversion, provides built‑in ASGI/WSGI adapters for FastAPI, Django, Flask, and implements a socket syscall bridge so standard Python DB drivers work via Hyperdrive. The team also pushed PEP 783 to stan…

    Hacker News front pagecloudflare.com9 minreleaseHN26241
  2. Cloudflare Introduces the Agent Development Lifecycle to Replace Traditional SDLC

    Cloudflare’s Agent Development Lifecycle (ADLC) replaces the classic SDLC with an autonomous, event‑driven workflow system that lets AI agents handle code generation, testing, deployment, and maintenance. The platform builds on Cloudflare Workflows and the new @cloudflare/ci library to spin up containers, run headless browsers, and chain steps with caching and credential support. Observability is…

    InfoQinfoq.com2 min
  3. Cloudflare Quick Tunnels

    Cloudflare Quick Tunnels let you expose a local service via an outbound‑only connection to Cloudflare’s edge network. The service gets a public URL (anycast across 335+ cities) with automatic TLS, DDoS protection, and no inbound ports. It’s positioned for short‑lived agents, webhooks, and testing loops, with JSON health output and no config files.

    Hacker News front pagecloudflare.com1 minreleaseHN831316
  4. 1 points

    Saving another 100TB of RAM with math (and Rust)

    Cloudflare reduced the memory footprint of its Pingora Backend Router by re‑examining the consistent‑hashing implementation in the pingora‑ketama library. By increasing the number of virtual hash points per server from the default 1 to the standard 160 (and applying weighted hashing based on disk capacity), they cut the per‑node overhead enough to reclaim >100 TB of RAM across the fleet. The post…

    Hacker News front pagecloudflare.com13 minHN478120lobste.rs33