This repository contains a comprehensive collection of examples demonstrating the capabilities of Falcon, a high-performance web server for Ruby. Falcon excels at handling concurrent connections, streaming responses, and real-time features that traditional Ruby web servers struggle with.
Falcon is an async web server built on top of the Async framework. It provides:
- High concurrency - Handle thousands of concurrent connections efficiently.
- HTTP/2 support - Native HTTP/2 with server push capabilities.
- Streaming responses - Perfect for real-time applications.
- WebSocket support - Built-in WebSocket handling.
- Low latency - Excellent performance for real-time features.
This application showcases 7 different examples, each demonstrating specific Falcon capabilities:
Demonstrates: HTTP response streaming and progressive rendering
- Streams a "99 bottles of beer" countdown in real-time
- Shows how Falcon handles long-running streaming responses
- Perfect for progress indicators, live logs, or data feeds
Demonstrates: WebSocket real-time communication with Redis pub/sub
- Multi-user real-time chat application
- WebSocket connections managed by Falcon
- Redis backend for message broadcasting across multiple clients
- Showcases Falcon's excellent WebSocket performance
Demonstrates: Interactive real-time applications with Live::View
- Real-time interactive game using WebSocket
- Demonstrates Live::View framework integration
- Shows how Falcon handles interactive, stateful applications
Demonstrates: Background job processing integration
- ActiveJob background job execution
- Job queue management and monitoring
- Shows how Falcon integrates with Rails' job processing
Demonstrates: AI/LLM streaming integration
- Streaming AI chat interface using Ollama
- Real-time AI response streaming
- Persistent conversation storage
- Perfect example of Falcon's streaming capabilities with AI
Demonstrates: Real-time game with Live::View
- Complete Flappy Bird game implementation
- Real-time game state synchronization
- High-performance game loop over WebSocket
- Demonstrates Falcon's low-latency capabilities
Demonstrates: Server-Sent Events (EventSource)
- Server-Sent Events for one-way real-time updates
- Connection pool monitoring
- Alternative to WebSocket for simple real-time updates
- Ruby (version specified in
.ruby-version). - Redis server running on localhost.
- SQLite3 (for database).
Clone the repository:
git clone https://github.com/socketry/falcon-rails-examples.git
cd falcon-rails-examplesInstall dependencies:
bundle installSetup the database:
bin/rails db:migrateEnsure Redis is running:
redis-serverStart the Falcon server:
bundle exec falcon serveThe application will be available at https://localhost:9292 (note: Falcon serves HTTPS by default).
If you have the datadog-agent running, you can enable instrumentation for Falcon:
$ TRACES_BACKEND=traces/backend/datadog METRICS_BACKEND=metrics/backend/datadog bundle exec falcon serveIf you'd like to log metrics and traces to the terminal:
$ TRACES_BACKEND=traces/backend/console METRICS_BACKEND=metrics/backend/console bundle exec falcon serveEach example demonstrates different aspects of Falcon's architecture:
- Streaming Controller: Basic HTTP streaming with
Rack::Response - WebSocket Integration: Using
Async::WebSocket::Adapters::Rails - Live::View Framework: Real-time view updates over WebSocket
- Background Jobs: Standard Rails ActiveJob integration
- Redis Integration: Pub/sub messaging for real-time features
- AI Integration: Streaming LLM responses with
async-ollama
Falcon provides significant performance improvements for:
- Real-time applications: WebSocket and SSE connections
- Streaming responses: Large file downloads, progress updates
- Concurrent users: Handling thousands of simultaneous connections
- I/O intensive operations: Database queries, API calls, file operations