---
title: "Do Apps Dream of Electric Sheep?"
description: "Railway's Scale to Zero stops idle containers, including databases, and wakes them on incoming TCP traffic using an L4 socket activation server rather than an HTTP-level proxy."
url: "https://swe.quest/articles/do-apps-dream-of-electric-sheep-0d21681e67e9dfcb"
canonical: "https://blog.railway.com/p/launch-week-01-scale-to-zero"
source: "Railway"
published: "2023-09-29"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 10
tags: ["serverless","networking","linux","containers","cost-optimization"]
---

# Do Apps Dream of Electric Sheep?

A post on [Railway](https://swe.quest/sources/railway.md), published 2023-09-29, 10 min read, Deep dive. Original: [https://blog.railway.com/p/launch-week-01-scale-to-zero](https://blog.railway.com/p/launch-week-01-scale-to-zero)

## Summary

Railway's Scale to Zero stops idle containers, including databases, and wakes them on incoming TCP traffic using an L4 socket activation server rather than an HTTP-level proxy. A sleep daemon uses cAdvisor to watch outbound packets and marks a container inactive after about 5–10 minutes with no egress. The container is then stopped and its port is added to an nftables set, so a high-priority PREROUTING rule (O(1) set lookup) redirects new connections to the activation server. That server reads SO\_ORIGINAL\_DST, starts the container, probes for a listening TCP server every 30 ms for up to 10 s, forwards bytes in both directions, and then removes the redirect so no connections are dropped. Cold starts return an HTTP response in under a second, but replicas, UDP support and the 30-minute forced connection close are noted as limitations, and an always-warm instance is still recommended for production.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Networking](https://swe.quest/tags/networking.md) (Infrastructure)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)

## Prerequisites

- Linux network namespaces ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))
- iptables/nftables basics
- TCP sockets ([easy posts on Networking](https://swe.quest/tags/networking.md?difficulty=easy))

## Keywords

Railway, nftables, cAdvisor, Envoy, SO\_ORIGINAL\_DST, socket activation, SOCKMAP

## Related posts

- [Serverless functions vs containers: CI/CD, database connections, cron jobs, and long-running tasks](https://swe.quest/articles/serverless-functions-vs-containers-ci-cd-database-connections-cron-jobs-and-e17b0efd79500afc.md): Railway · 2025-12-16 · Medium · 11 min read · Serverless, Containers, Deployment, Schema migrations, Cloud platforms
  Serverless functions and container platforms differ in execution model, which changes how you handle deploys, database access, cron jobs, rollbacks and long-running work.
- [Slack’s Migration to a Cellular Architecture](https://swe.quest/articles/slack-s-migration-to-a-cellular-architecture-7c9634739e313402.md): Slack Engineering · 2023-08-22 · Medium · 8 min read · Resilience, Load balancing, Distributed systems, Cloud platforms, SRE
  Slack moved its critical user-facing services in us-east-1 to a cellular architecture where each availability zone is a cell that can be drained, after a 2021 gray-failure network outage in one AZ caused user-visible errors across all AZs.
- [Railway vs Cloudflare: How Their Architectures Differ and When to Use Each](https://swe.quest/articles/railway-vs-cloudflare-how-their-architectures-differ-and-when-to-use-each-da6a8e4c1e4636fe.md): Railway · 2025-11-28 · Medium · 15 min read · Serverless, CDN & edge, Cloud platforms, System design, Containers
  Railway and Cloudflare's Developer Platform feel similar on the surface but rest on opposite compute models.
- [WireGuard at Modal: Static IPs for serverless containers](https://swe.quest/articles/wireguard-at-modal-static-ips-for-serverless-containers-f9b6b3f9bd58963d.md): Modal · 2024-12-02 · Hard · 14 min read · Networking, Linux, Serverless, Go, Multi-tenancy
  Modal built vprox, a high-availability Go VPN proxy on WireGuard, to give multi-tenant serverless containers static outbound IPv4 addresses for things like database IP allowlists.
- [Thundering herd of circuit breakers](https://swe.quest/articles/thundering-herd-of-circuit-breakers-b2ab1d42eebffb68.md): Zalando Engineering · 2026-10-07 · Medium · 9 min read · Resilience, Incidents & postmortems, Observability, Kubernetes, Capacity planning
  A client's circuit breaker stayed open for hours because its half-open probes hit a service that the HPA had scaled down to three pods.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
