Introduction
Drogon is a C++ web application framework designed for building extremely fast HTTP services. Named after the dragon in Game of Thrones, it prioritizes raw throughput and minimal overhead. Drogon consistently ranks among the top frameworks in the TechEmpower benchmarks, making it a strong choice for latency-sensitive backend services.
What Drogon Does
- Serves HTTP/1.1 and HTTP/2 requests with non-blocking asynchronous I/O
- Provides a controller-based routing system with support for RESTful APIs
- Includes built-in WebSocket support for real-time bidirectional communication
- Offers an asynchronous ORM (Drogon ORM) for PostgreSQL, MySQL, and SQLite
- Generates boilerplate code via the
drogon_ctlcommand-line tool
Architecture Overview
Drogon runs an event loop per thread using epoll (Linux), kqueue (macOS/BSD), or IOCP (Windows) for non-blocking socket I/O. Incoming requests are dispatched to handler coroutines or callback-based controllers. The framework manages a thread pool for blocking operations and database queries. All handler interfaces default to asynchronous mode where responses are returned via callbacks or C++20 coroutines.
Self-Hosting & Configuration
- Configuration is done via a JSON file (
config.json) or programmatically inmain.cc - Listeners, thread count, session settings, and SSL certificates are set in the config
- Static file serving is built in and configured with
document_rootandupload_path - Database connections are pooled and configured per-database with async query support
- The
drogon_ctltool generates controllers, filters, plugins, and model code from templates
Key Features
- C++20 coroutine support for writing async code that reads like synchronous code
- Built-in support for gzip/brotli compression, sessions, cookies, and file uploads
- CSP (C++ Server Pages) template engine for server-side rendered HTML views
- Plugin system for extending the framework with custom middleware and services
- Cross-platform: runs on Linux, macOS, FreeBSD, OpenBSD, HaikuOS, and Windows
Comparison with Similar Tools
- Crow — Header-only C++ micro-framework; simpler API but fewer built-in features and no ORM
- Oat++ — C++ web framework with built-in serialization; similar performance but different API style
- Pistache — C++ REST framework; lightweight but less actively maintained
- Actix Web (Rust) — High-performance Rust framework; similar benchmark rankings but different language ecosystem
- FastAPI (Python) — Developer-friendly Python framework; much easier to write but orders of magnitude slower
FAQ
Q: How does Drogon compare in benchmarks? A: Drogon consistently ranks in the top tier of the TechEmpower Web Framework Benchmarks across JSON serialization, database queries, and plaintext categories.
Q: Does Drogon support C++20 coroutines?
A: Yes. Drogon supports C++20 coroutines for writing async handlers with co_await, making the code much more readable than callback-based approaches.
Q: What databases does the ORM support?
A: Drogon ORM supports PostgreSQL, MySQL/MariaDB, and SQLite with async query execution and connection pooling. Models are generated from the database schema using drogon_ctl.
Q: Can I use Drogon for microservices? A: Yes. Drogon's small binary size, fast startup, and high throughput make it well-suited for containerized microservices behind a load balancer.