Home > Backend Development > Golang > Is it possible to create a service in Go that both consumes a message stream (from Kafka) and reads REST API requests?

Is it possible to create a service in Go that both consumes a message stream (from Kafka) and reads REST API requests?

王林
Release: 2024-02-12 18:06:05
forward
929 people have browsed it

是否可以在 Go 中创建一个既使用消息流(来自 Kafka)又读取 REST API 请求的服务?

Question content

I recently read an article "Sharing data between large-scale microservices"

This picture is about asynchronous connections.

If I remember correctly, the Order page in this picture The service appears to be able to read the message stream from Kafka, and also read REST API requests from the front-end application.

So, I'm wondering if it's possible to write a service that can do both tasks at the same time:

  • Read the message stream from Kafka
  • Read REST API request

Only in 1 service, such as in Go.

Is this a good idea?

Workaround

Yes, you can definitely write a Go service that consumes from Kafka and exposes a REST endpoint. However, this is not an ideal design decision.

The Kafka-based streaming system allows asynchronous communication between producers and consumers. However, REST API-based systems communicate synchronously between the caller and the callee.

The availability guarantees are different between synchronous and synchronous mode communication. A system based on Kafka Streams will have different availability guarantees than a REST API. In a streaming system, we focus on message processing throughput, while in end-to-end synchronous communication, latency is the main concern (you don't want the caller to wait for a long time to get the result).

If we put these two types of systems in one service, it will be difficult to understand the availability of the service. Additionally, an asynchronous part or a synchronous part of a service may play into a noisy neighbor on the other side, making the service unavailable.

Therefore, in general, it is recommended to treat REST-based APIs and Kafka streams as two independent services.

The above is the detailed content of Is it possible to create a service in Go that both consumes a message stream (from Kafka) and reads REST API requests?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template