AI summary by TwinMind
Serverless With Servers? FLAME is...weird
Theo - t3․gg
25m 38s
Introduction to Flame Pattern
- Flame = "Fleeing Lambda Application for Modular Execution"
- Alternative serverless approach using entire app as Lambda with modular parts on short-lived infrastructure
- No rewrites, no proprietary runtimes, no complex layers
- Created by Chris McCord and team at Fly.io for Elixir community
Problems with Traditional Serverless
- Complexity increases with elastic scaling needs
- Functions-as-a-Service creates labyrinth of complexity
- Lambda timeout limits (15 minutes) problematic for video transcoding
- Requires splitting videos into chunks, orchestrating Lambda workflows
- Dependencies on SQS, S3, API Gateway for communication
- Dev/test environments become "fate worse than death"
- Mental overhead for building, maintaining, debugging multi-piece architecture
Flame Implementation Example
- Video thumbnail generation use case
- Traditional approach:
generate_thumbnailsfunction with FFmpeg processing - Flame approach: wrap in
flame.call(MyApp.FfmpegRunner, &generate_thumbnails/2) - 3-second cold start on Fly.io infrastructure
- Automatic variable passing and result return
- Runner connects back to parent node, executes function, returns result
- Can configure idle timeout, max concurrency, scale-to-zero behavior
Technical Architecture
- Provisions new runner with app info
- New runner connects to parent node
- Parent sends function for execution
- Runner executes and returns result, then shuts down
- Entire application runs on runner (database connections and all)
- Only executes specific function after startup
Database Connection Concerns
- Biggest serverless issue: database connection limits
- Pattern doesn't solve this problem, might make it worse
- Could overwhelm database with unexpected connections
- Solution: implement pool of runners for hot startup and database pooling
Flame vs Functions-as-a-Service Complexity
- Traditional FaaS requires: custom encoders/decoders, HTTP streaming, timeout handling, workflow orchestration
- Flame eliminates: separate service deployments, S3/SQS dependencies, dev/test complexity
- Local development runs on local backend, production uses Fly backend
Flame Backend Implementation
- Under 200 lines of code with docs
- Single dependency: HTTP client for requests
- Works with any cloud providing API to provision servers
- Fly backend guarantees same region deployment
- Can stream files between parent and child nodes using Elixir's distributed capabilities
Background Jobs vs Flame
- Distinction between durability guarantees and elastic execution
- Queues important for reliability, retries, error handling
- Flame better for operations not needing durability (user left app, real-time processing)
- Can combine: durable job queue dispatching flame calls for actual processing
Elixir-Specific Features
- Supervised process approach ideal for configuration
- Define elastic pools with min/max limits, concurrency controls
- Process placement using lightweight green threads
- Remote monitoring with failsafe mechanisms
- Automatic orphan resource prevention
- Code version synchronization across cluster
Language Portability
- Elixir ideal due to BEAM VM distributed messaging capabilities
- JavaScript proof-of-concept exists
- Any language with reasonable concurrency primitives can implement pattern
- Requires handling: elastic pool scaling, hot/cold starts, remote monitoring, deployment freshness
Configuration Example
- Start callback defines flame pool for video transcoding
- Max 10 runners, 5 concurrent FFmpeg operations, scale to zero
- 30-second idle timeout before shutdown
- Conditional web server startup (only if serving web traffic)
- Database repo accessible across all runners
