Actix Web Interview Questions
Prepare for your next Rust backend role. Explore these carefully curated interview questions covering architecture, extractors, state management, and more.
Basics & Architecture
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust. It achieves its speed by being built on top of Tokio (an asynchronous runtime) and utilizing an isolated thread-per-core architecture. Instead of sharing a single thread pool with locks, Actix Web spawns an isolated event loop worker for each logical CPU core, effectively eliminating lock contention (zero mutexes required for request routing).
While the original framework was deeply tied to the `actix` actor framework, Actix Web v4 is no longer an actor-based web framework. The core handlers and routing are built entirely using asynchronous Rust (`async`/`await`) and Tokio. You can still integrate with the `actix` actor framework if you need actors (e.g., for WebSockets), but standard HTTP requests do not spawn or require actors.
It uses a combination of multi-threading and asynchronous I/O. When `HttpServer::new` is run, it looks at the system's CPU cores and spawns a number of worker threads (usually one per logical core). Each worker thread runs its own single-threaded Tokio local pool (`LocalSet`). Asynchronous tasks (HTTP requests) are multiplexed concurrently on these individual threads without blocking.
Extractors & Handlers
An extractor is a type that implements the FromRequest trait. Extractors allow you to declaratively pull data out of an incoming HTTP request simply by adding them as arguments to your handler functions. Common extractors include web::Json, web::Path, web::Query, and web::Data. If an extractor fails (e.g., invalid JSON), Actix Web automatically returns a 400 Bad Request response without your handler ever being called.
You use web::Data<T>. Application state is initialized in the `HttpServer::new` closure using App::new().app_data(web::Data::new(my_state)). It can then be extracted in any handler. Because Actix spawns multiple workers, web::Data uses an Arc internally to safely share the same memory pointer across threads. Any mutable state inside it must use thread-safe synchronization (like Mutex or RwLock).
Responder is a trait implemented for types that can be converted into an HttpResponse. Returning impl Responder from a handler allows you to return types like String, &str, web::Json, or HttpResponse directly. Actix Web will automatically call the respond_to() method to convert these types into a proper HTTP response with the correct headers (like Content-Type).
Error Handling & Middleware
Custom error handling is done by implementing the ResponseError trait for your custom error types. This trait requires you to define a status_code() and an error_response(). Once implemented, you can return Result<T, MyCustomError> from your handlers. When an error occurs, Actix Web automatically calls the trait methods to convert your Rust error into an HTTP response.
Middleware hooks into the request/response lifecycle. It can inspect or modify requests before they reach handlers, and responses before they are sent to the client. Typical uses include Logging (Logger), Authentication, CORS, and Compression. Middleware is added using the .wrap() method on the App instance.
Want to dive deeper?
The best way to prepare for an interview is to build something real. Head over to our Learn section or check out the official docs.