Reactor Pattern

Learn about the reactor pattern.

Introduction

The reactor pattern is generally used in I/O heavy applications. Let’s suppose we have an application that gets a lot of requests from the client.

Let’s assume that we have a situation where we have a thread that is listening to the client’s requests, processes the request, and sends back the response to the client. The problem is that the load on that specific thread increases significantly when there are too many requests. This can significantly delay other requests that then have to wait before getting processed.

According to the reactor pattern, there should be a main thread (reactor) and worker threads (handlers) instead of a single thread. The main thread’s job is only to communicate with the client and other worker threads. Worker threads (handlers) are threads that are responsible for the processing. Due to the worker thread, the main thread only handles client requests.

Through the reactor pattern, we can design event-driven applications that can accept multiple client requests simultaneously and distribute them to different service providers.

Get hands-on with 1400+ tech skills courses.