# Scale-to-zero managed realtime

> Gregale terminates long-lived WebSocket and Server-Sent Events connections at the edge, handles heartbeats while your backend stays parked, and wakes your app only when messages arrive or you broadcast.

Category: Realtime · Maturity: Beta · Plans: Hobby, Pro, Scale · Updated 2026-11-26

Holding idle WebSockets inside your own backend forces at least one instance to remain running around the clock. Gregale Managed Realtime decouples persistent socket termination from your application compute so clients stay connected for hours while you pay only for actual request handling.

## Create a managed realtime endpoint and broadcast from anywhere

```bash
# Create an endpoint backed by your app callbacks (pipe secret via stdin)
printf '%s\n' "$CALLBACK_TOKEN" | gregale realtime create my-app \
  --callback-url https://my-app.example.com \
  --callback-auth-token-stdin

# Publish to a channel from your backend, CI job, or CLI without holding sockets
gregale realtime publish my-app <endpoint-id> notifications --data '{"status":"ready"}'
```

## Key capabilities

- **Heartbeats handled while parked:** Clients connect to wss://<your-app-host>/__gregale/realtime/<endpoint-id> over WebSocket or HTTPS SSE. Gregale maintains heartbeats while your app stays at zero resident RAM.
- **Wake-on-message callbacks:** Incoming client messages and connection lifecycle hooks invoke your backend over HTTP callbacks; once processed, the app parks again after its idle timeout.
- **Zero-connection backend broadcasts:** Publish to channels or send directly to a connection via the Node/Python/Go SDKs, REST API, or CLI from short-lived handlers or background jobs.
- **Explicit trade-off vs. direct WebSockets:** Self-terminated WebSockets (--websocket-enabled) remain available when sockets must terminate inside the app, whereas Managed Realtime maximizes savings on long, sparse connections.

## Typical PaaS vs. Gregale

| Capability | Typical PaaS | Gregale |
|---|---|---|
| Idle client WebSocket connections | Keeps app container running and billed 24/7 | Held by Gregale edge while app stays parked at $0 |
| Client transport support | Separate third-party realtime SaaS required for sleep | Built-in WebSocket and HTTPS Server-Sent Events |
| Fan-out publish from serverless jobs | Requires Redis pub/sub + dedicated socket fleet | Single SDK/API/CLI publish call wakes zero extra servers |

## Documentation

- [Managed realtime](https://gregale.dev/docs/realtime.md)
- [Scale to zero](https://gregale.dev/docs/scale-to-zero.md)
- [SDKs](https://gregale.dev/docs/sdks.md)
- [Billing](https://gregale.dev/docs/billing.md)

## Related guides

- [websockets-sse-scale-to-zero](https://gregale.dev/articles/websockets-sse-scale-to-zero.md)
- [scale-to-zero-without-cold-starts](https://gregale.dev/articles/scale-to-zero-without-cold-starts.md)
- [hard-cloud-spend-caps](https://gregale.dev/articles/hard-cloud-spend-caps.md)

## Research

- [paas-intermittent-api-cost-model-2026-11-25](https://gregale.dev/research/paas-intermittent-api-cost-model-2026-11-25.md)

## Runnable starters on GitHub

- [Scale-to-Zero WebSockets & SSE](https://github.com/gregale-dev/scale-to-zero-websockets) (Node 22 · Managed Realtime): Hold thousands of idle WebSocket or SSE connections on Gregale Managed Realtime with heartbeat offload and HTTP callbacks so your app parks at $0 compute.

Browse all starters: https://gregale.dev/templates.md

## Frequently asked questions

### Which parts of Managed Realtime are Beta today vs. Preview?

Realtime endpoints, WebSocket and SSE connections held while your app is parked, callbacks, live publish, direct/principal send, connection operations, and fair-use limits are Beta on every paid plan. Retained history/resumable protocol, presence, occupancy, tickets, and worker groups are per-account Preview.

### Does holding 1,000 open WebSocket clients bill compute on my app?

No app compute is billed while your app is parked and connections are idle because Gregale handles heartbeats at the realtime edge. Your app is billed only during active callbacks or backend requests.

### What if I want to handle raw WebSocket frames directly inside my app process?

You can still enable --websocket-enabled on the app directly. Keep in mind those sockets terminate inside your running VM, which keeps that instance active and billed while connections stay open.

Canonical URL: https://gregale.dev/features/realtime-scale-to-zero
