Event Driven Architecture
Modern applications are constantly changing and require a high degree of horizontal scalability. Therefore it is important to leverage tools and practices that allow for rapid response to changes in application state.
In this blog post, we’re going to discuss why event-driven architecture is important and how it can be leveraged to develop horizontally scalable architectures. Afterwards, you’ll get introduced to a popular event-driven auto-scaling framework for Kubernetes called KEDA, and how it can be used to enable event-driven architecture.
What is event-driven architecture?
When an application changes state, an event is produced, and in modern distributed applications it is common to leverage these events to trigger and communicate with the various microservices contained within. This is known as an event-driven architecture, and it consists of three components:
- Event Producers - Publish events to router
- Event Routers - Filter and push events to consumer
- Event Consumers - Consume the event
What is auto-scaling?
The Kubernetes API provides the ability to dynamically adjust to demand by automatically scaling pods up and down without the need for outside intervention. This allows for services to adjust availability up for peak traffic times and then scale back down to optimize resource usage.
Autoscaling is one of the most powerful features within Kubernetes and a keystone in developing an event-driven architecture.
What is KEDA?
While Kubernetes provides autoscaling out of the box, it does not natively provide a solution for event-driven auto-scaling. This is where KEDA comes into play. KEDA is an Kuberentes-native event-driven autoscaler that allows you to enable the scaling of any container based on a variety of processed events.
KEDA has out of the box scalers for processing a variety of different events, such as:
- Prometheus
- InfluxDB
- Redis Streams
- And many more!
Application Autoscaling Made Easy With Kubernetes Event-Driven Autoscaling - Tom Kerkhove, Codit
How does KEDA enable event-driven auto-scaling?
KEDA works in conjunction with the Kubernetes Horizontal Pod Autoscaler to process events and scale pods according to specified triggers. The tool performs two key roles:
- Agent - KEDA activates and deactivates Kubernetes Deployments to scale to and from zero on no events. This is one of the primary roles of the keda-operator container that runs when you install KEDA.
- Metrics - KEDA acts as a Kubernetes metrics server that exposes rich event data like queue length or stream lag to the Horizontal Pod Autoscaler to drive scale out.
Leveraging KEDA for event-driven auto-scaling
While the traditional method of CPU-based auto-scaling has its place, it fails to support certain complex metrics that support the multi-dimensional scaling needs of modern applications. This has the potential to cause application failure due to load and does not fulfill the needs of event-driven architectures.
Luckily KEDA comes equipped with a variety of scalers out of the box such as Prometheus and InfluxDB. This allows you to set certain thresholds for horizontal scaling based on the complex metrics event-driven architectures need.
For example, with the Prometheus scaler, you’ll have the ability to trigger the scaling of pods based on the http_requests_total threshold. In practice, it would look something like this:
The serverAddress indicates where Prometheus is running which contains the configured metric defined in metricName or query.
Enabling KEDA auto-scaling with Zeet
While there are a variety of ways to implement KEDA in your application, (Helm, Operator Hub, YAML), a good place for you to start is Zeet’s self-service DevOps platform.
With Zeet, deploying your event-driven application is as easy as turning on auto-scaling and selecting a custom KEDA scaler as seen below:
Zeet also offers a free trial for anyone that is interested in trying out these features for themselves.
Conclusion
That concludes this blog post! Hopefully you’ve gotten a good introduction to how event-driven architecture enables modern applications to scale horizontally. If you’re interested in getting started with KEDA on your own, take a look at our supporting blog post here.