Knative: AI event-driven scenarios


As a mainstream open source serverless framework, Knative provides event-driven capabilities in addition to application deployment and automatic flexibility. In the face of AI scenarios, users have high requirements for fine processing of events and saving resource costs. Here we introduce how to achieve event-driven, event distribution and automatic resource elasticity through Knative, which well meets the demands of user scenarios. This article will introduce from the following three aspects:

• Event-driven framework: Knative Eventing

• Event-driven engine: introduction to event source

• AI event-driven scenario practice

Knative model

Let's take a look at the two core modules in Knative as a whole. In Serving, the application model is provided through Knative Service, which supports multi-version management, automatic elasticity and traffic grayscale release. Eventing provides an event-driven framework, including event source and broker/trigger model. Next, we mainly introduce the native event.

Event-driven framework: Eventing

Knative's Eventing provides a complete event model, which can easily access the events of various external systems. After the event is accessed, it flows internally through the CloudEvent standard, and provides a very ideal way for event processing in combination with the Broker/Trigger mechanism.

• The services provided by Knative Eventing are loosely coupled and can be independently developed and deployed. Services can be used across platforms (such as Kubernetes, VMs, SaaS or FaaS)

• The producers and consumers of the event are independent of each other.

• The community provides multiple out-of-the-box event sources

• Support third-party messaging systems and provide flexible scalability.

Key characteristics - event rules

In Event, event flow and distribution are carried out through Broker/Trigger. Distribution cannot be separated from rule setting. Trigger provides rich rule setting capabilities, as shown in the figure:

• The function of Trigger's filter is to filter the content of events.

• Support filtering of the Attribute of Event and the content of Data.

• Common Expression Language (CEL) expression filtering is supported.

• Support filtering through SourceAndType

Event-driven engine: event source

Event sources are event-driven engines, and the Knative community provides rich event sources, such as Kafka, GitHub, etc. In addition, it also accesses event sources of message cloud products, such as MNS, RocketMQ, etc.

This complete event system can easily implement event-driven scenarios as follows:

• Automatic CICD

• AI audio and video scene

• For example, connect with events of various cloud products, so as to automatically trigger a service when updating the status of cloud products

RocketMQ event source

Message Queuing RocketMQ is a distributed messaging middleware with low latency, high concurrency, high availability and high reliability built by Alibaba Cloud based on Apache RocketMQ. The RocketMQ version of message queue can not only provide asynchronous decoupling and peak-shaving and valley filling capabilities for distributed application systems, but also have the features of massive message accumulation, high throughput, reliable retry and so on required by Internet applications.

RocketMQSource is the RocketMQ event source of the Knative platform. It can forward the messages of RocketMQ cluster to the Knative platform in real time in the form of Cloud Event. It is a connector between Apache RocketMQ and Knative.

• Docking RocketMQ message system

• Message distribution to Knative service

Kafka event source

Message Queuing Kafka is a distributed message queue service with high throughput and high scalability built by Alibaba Cloud based on Apache Kafka. It is widely used for log collection, monitoring data aggregation, streaming data processing, online and offline analysis, etc. It is one of the indispensable products in the big data ecosystem. Alibaba Cloud provides fully managed services. Users do not need to deploy O&M, and it is more professional, reliable and secure.

The Knative community provides Kafka event sources, supports the open source community Kafka and Alibaba Cloud Kafka products:

• Docking Kafka message system

• Message distribution to Knative service

AI event-driven scenario practice

Next, take Kafka event source as an example to introduce a typical message-driven scenario.

The customer is an online live broadcast system. There are a large number of live broadcast visits every day. The number of visits fluctuates elastically according to the popularity of live broadcast, and there is an irregular surge; At the same time, the live broadcast system supports users' online interaction. The interaction behavior will be pushed to the server for data and AI processing through the message service (Kafka) in real time, and the processing results will be pushed back to the video stream in real time to interact with the live video. The processing of message data mainly has the following technical challenges:

1. Business elasticity fluctuates and message concurrency is high.

2. Interactive real-time response, low latency.

In order to meet the requirements of the customer system for flexible fluctuation, high concurrency and low latency of message processing, the customer chooses to use AliCloud's Knative service for flexible data processing. Alibaba Cloud Knative fully meets the needs of users. On the basis of compatibility with the k8s standard, it provides container elastic scheduling based on events/messages. The number of application instances expands and shrinks in real time along with the peaks and valleys of business, which truly achieves the cloud computing capability of on-demand and real-time flexibility. The whole process is fully automated, greatly reducing the mental burden of business developers on infrastructure. Next, we use an example to simulate the user's scenario


• Create an ACK/ASK cluster and select [Knative] for installation

• For existing ASK clusters, deploy Knative reference

• Deploy event-driven Eventing

Operation steps

1. Deploy event gateway

On the Knative component management console, select "Kourier" and "EventGateway" addon components to deploy

2. Deploy event sources. Select Kafka event source for deployment.

3. Deployment Services

Here we deploy a Knative service event-display to receive events.

4. Create event source CR

Create the KafkaSource resource, set the topic, consumerGroup, Kourier gateway address corresponding to Kafka, and the service event-display for consumption events.

Results of enforcement

We send messages to the kafka message queue through the client to verify the results

This article introduces the Knative driving framework: Eventing, and supports Kafka and RocketMQ event source access. It introduces how to combine message service and Knative in the AI event-driven scenario.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us