Stateless Instances
Run multiple instances across Cloudflare's network
To simply proxy requests to one of multiple instances of a container, you can use the getRandom function:
import { Container, getRandom } from "@cloudflare/containers";
const INSTANCE_COUNT = 3;
class Backend extends Container {  defaultPort = 8080;  sleepAfter = "2h";}
export default {  async fetch(request: Request, env: Env): Promise<Response> {    // note: "getRandom" to be replaced with latency-aware routing in the near future    const containerInstance = await getRandom(env.BACKEND, INSTANCE_COUNT);    return containerInstance.fetch(request);  },};Was this helpful?
- Resources
 - API
 - New to Cloudflare?
 - Directory
 - Sponsorships
 - Open Source
 
- Support
 - Help Center
 - System Status
 - Compliance
 - GDPR
 
- Company
 - cloudflare.com
 - Our team
 - Careers
 
- © 2025 Cloudflare, Inc.
 - Privacy Policy
 - Terms of Use
 - Report Security Issues
 - Trademark