Event-driven architecture manages concurrent operations by responding to events instead of dedicating threads to tasks or blocking while waiting. An event loop monitors network connections, file descriptors, timers, and other sources, then dispatches detected events to handlers. A single thread can therefore coordinate many I/O-bound operations with relatively low resource overhead. section 9.2.4
Web server with asynchronous database work
A web server can accept thousands of connections without assigning one thread to every request. When a request needs a database query, it starts the query asynchronously and handles other events. Query completion later triggers a continuation that resumes request processing. section 9.2.4
A practical event loop follows this division of responsibility:
- Wait for events from operating-system interfaces such as epoll or io_uring on Linux and kqueue on macOS; waiting may block when no work exists. section 9.2.4
- Dispatch each detected event to its handler, which must not block because it would stop the loop from processing other events. section 9.2.4
- Defer unfinished work and resume it when a later completion event signals that the required operation has finished. section 9.2.4
Figure 9.3 The event loop is the heart of event-based concurrency—it polls for events from the OS and invokes appropriate event handlers. For example, if a packet arrives from the network, the event loop polls for them using an I/O polling API such as io_uring, epoll, or kqueue, and then hands over the received messages to event handlers. When the event-loop polling is done, the event loop calls itself to continue polling.
The event-loop diagram shows the polling-and-dispatch cycle, including how operating-system I/O notifications reach event handlers before polling resumes. section 9.2.4
The model is especially effective for I/O-bound applications, where thread-based designs would spend substantial time waiting. It reduces resource overhead, but handler design is critical: one blocking handler can prevent every other event from being processed. section 9.2.4 section 9.7









