☁️ Cloud

Fly.io

Fly.io

A platform for deploying apps to edge locations worldwide. Container-based.

Detailed Explanation

Fly.io is a cloud platform that lets you deploy applications at the edge across more than 35 regions worldwide. It uses Firecracker microVM technology to provide faster boot times than containers and strong isolation, and runs apps at the location closest to users.

Key features of Fly.io:

  • Global edge deployment: Deploy to 35+ regions worldwide within seconds. Includes the Seoul region
  • Firecracker microVM: The technology AWS uses for Lambda. 125ms boot
  • Anycast networking: Automatically routes users to the nearest instance
  • Fly Machines: Millisecond-level provisioning. Automatically start/stop as needed
  • Fly Postgres: Globally distributed PostgreSQL cluster

Pricing features:

  • Free tier: 3 shared-cpu-1x VMs, 160GB outbound traffic
  • Pay-as-you-go: CPU/memory billed per second. No charge when stopped
  • Scale to zero: Reduce costs by automatically stopping when there is no traffic

Code Example

# Fly CLI 설치 (macOS) brew install flyctl # 로그인 fly auth login # 새 앱 생성 및 배포 (Dockerfile 기반) fly launch # ? Would you like to copy its configuration to the new app? Yes # ? Choose a region for deployment: nrt (Tokyo, Japan) # ? Would you like to set up a Postgresql database now? No # 배포 fly deploy # 앱 상태 확인 fly status # 로그 확인 fly logs # SSH 접속 fly ssh console # 환경 변수 설정 fly secrets set DATABASE_URL="postgres://..." # 스케일링 (인스턴스 수) fly scale count 3 # 리전 추가 (글로벌 배포) fly regions add icn # 서울 fly regions add sin # 싱가포르 fly regions add fra # 프랑크푸르트 # 머신 크기 조정 fly scale vm shared-cpu-2x --memory 1024 # 자동 스케일링 설정 fly autoscale set min=2 max=10 # PostgreSQL 생성 fly postgres create --name my-db --region nrt # 앱에 DB 연결 fly postgres attach my-db
# fly.toml - Fly.io 앱 설정 파일 app = "my-app" primary_region = "nrt" # 도쿄 (한국에서 가장 가까움) [build] dockerfile = "Dockerfile" [env] NODE_ENV = "production" PORT = "8080" [http_service] internal_port = 8080 force_https = true auto_stop_machines = true # 유휴 시 자동 정지 auto_start_machines = true # 요청 시 자동 시작 min_machines_running = 1 # 최소 1개는 항상 실행 processes = ["app"] [http_service.concurrency] type = "requests" hard_limit = 250 soft_limit = 200 [[services]] protocol = "tcp" internal_port = 8080 [[services.ports]] port = 80 handlers = ["http"] [[services.ports]] port = 443 handlers = ["tls", "http"] [[services.tcp_checks]] grace_period = "10s" interval = "15s" timeout = "2s" [[services.http_checks]] interval = "10s" timeout = "2s" grace_period = "5s" method = "GET" path = "/health" protocol = "http" [[vm]] cpu_kind = "shared" cpus = 1 memory_mb = 512 # 멀티 리전 배포 설정 [[regions]] region = "nrt" # 도쿄 count = 2 [[regions]] region = "icn" # 서울 (가능한 경우) count = 1 [[regions]] region = "sin" # 싱가포르 count = 1 # 볼륨 마운트 (영구 스토리지) [[mounts]] source = "data" destination = "/data" # 릴리스 명령어 (배포 후 실행) [deploy] release_command = "npm run db:migrate"
# Fly.io 멀티 리전 배포 전략 # 1. 리전별 인스턴스 배포 fly regions add nrt icn sin syd # 현재 리전 확인 fly regions list # Region Pool: # icn (Seoul) # nrt (Tokyo) # sin (Singapore) # syd (Sydney) # 2. 리전별 스케일링 fly scale count 2 --region nrt fly scale count 2 --region icn fly scale count 1 --region sin # 3. 리전별 환경 변수 (선택적) # Fly는 FLY_REGION 환경 변수를 자동 주입 # 앱 코드에서 활용 가능 # Node.js 예제 - 리전 인식 코드 cat <<'EOF' > server.js const express = require('express'); const app = express(); // Fly.io가 주입하는 환경 변수 const region = process.env.FLY_REGION || 'unknown'; const instanceId = process.env.FLY_ALLOC_ID || 'local'; app.get('/', (req, res) => { res.json({ message: 'Hello from Fly.io!', region: region, instance: instanceId, timestamp: new Date().toISOString() }); }); app.get('/health', (req, res) => { res.status(200).json({ status: 'healthy', region }); }); // 리전별 데이터 처리 app.get('/nearest', (req, res) => { // 사용자는 자동으로 가장 가까운 리전으로 라우팅됨 res.json({ message: `Served from ${region}`, latency: 'minimal' }); }); const port = process.env.PORT || 8080; app.listen(port, () => { console.log(`Server running in ${region} on port ${port}`); }); EOF # 4. Fly Replay - 요청을 다른 리전으로 리플레이 # 헤더로 특정 리전 강제 지정 curl -H "fly-replay: region=nrt" https://my-app.fly.dev/ # 앱 코드에서 리플레이 응답 # res.setHeader('fly-replay', 'region=nrt'); # 5. Fly Postgres 글로벌 분산 fly postgres create --name my-global-db fly postgres attach my-global-db # 읽기 전용 복제본 추가 fly volumes create pg_data --region sin --size 10 fly machine clone <primary-machine-id> --region sin # 애플리케이션에서 읽기/쓰기 분리 # PRIMARY: fly-replay 헤더로 primary 리전으로 라우팅 # REPLICA: 로컬 리전 복제본에서 읽기

Practical Conversation Example

Platform Selection Meeting
"Fly.io vs Vercel vs AWS — which one should we use?" "It depends on the purpose. Vercel specializes in frontend/Next.js and focuses on serverless functions. Fly.io runs full containers, so it is good for backend APIs, WebSockets, and stateful apps. AWS is for when you need large-scale infrastructure. If a small team wants to deploy a global service quickly, Fly.io is a perfect fit."
Cost Optimization Discussion
"How do you manage costs on Fly.io?" "Scale to zero is the key. If you set auto_stop_machines=true in fly.toml, VMs stop automatically when there are no requests and you are not charged. However, there are cold starts, so keep at least one running with min_machines_running=1. For development environments, you can stop them completely."
Architecture Review
"I want to reduce API latency for global users." "Deploy multi-region with Fly.io. If you place instances in Seoul, Tokyo, and Singapore, Asia is covered, and Anycast automatically connects users to the nearest instance. For the DB, place Fly Postgres replicas in each region, or use a pattern where only read requests are handled locally."
Interview Question
"How does Fly.io's Firecracker microVM differ from a Docker container?" "Docker shares the kernel with the host, but Firecracker gives each workload a dedicated mini kernel, so security isolation is strong. AWS Lambda and Fargate use the same technology too. Boot time of 125ms can also be faster than containers. The downside is that Docker images cannot be used as-is, and Fly converts them."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

Cautions

⚠️
Cold start: When auto_stop_machines is enabled, restarting a stopped VM takes a few seconds. For latency-sensitive services, set min_machines_running.
⚠️
Volume constraints: Fly Volumes are bound to a single region/single instance. If you need multi-instance persistent storage, use object storage such as S3/R2.
⚠️
Region availability: Not all regions are always available. The Korea (icn) region may still be limited, so consider Tokyo (nrt) as an alternative.
⚠️
Free tier limits: There are limits of 3 shared-cpu-1x VMs and 256MB of memory. A paid plan is required for production workloads.

Related Terms

Learn More