Is it possible to create a service that consume both message streaming (from Kafka) and also read REST API request, in Go?

huangapple go评论70阅读模式
英文:

Is it possible to create a service that consume both message streaming (from Kafka) and also read REST API request, in Go?

问题

我最近阅读了一篇文章《在高规模环境下的微服务之间共享数据》。这篇文章讨论了异步连接的问题。如果我没有错的话,这张图片中的**订单页面(Order Page)**服务似乎可以从Kafka读取消息流,并且还可以从前端应用程序读取REST API请求。所以,我想知道是否有可能编写一个服务,可以同时实现以下两个功能:

  • 从Kafka读取消息流
  • 读取REST API请求

比如说,用Go语言实现这个服务是否可行?同时,这样做是否是一个好主意?

英文:

I recently read an article Sharing Data Between Microservices on High Scale<br>

There's this image that is about Asynchronous connection. <br>
Is it possible to create a service that consume both message streaming (from Kafka) and also read REST API request, in Go?

If I make no mistake, the Order Page service in this picture seems to be able to read messages streaming from Kafka, and also read REST API request from front-end app.<br>

So, I wonder if it's possible to write a service that can do both :

  • Read messages streaming from Kafka
  • Read REST API request<br>

In just 1 service, for instance in Go.<br>

Also whether is it a good idea ?

答案1

得分: 1

是的,你绝对可以编写一个消费Kafka并暴露REST端点的Go服务。然而,这不是一个理想的设计决策。

基于Kafka的流式系统允许生产者和消费者之间的异步通信。然而,基于REST API的系统则进行调用方和被调用方之间的同步通信。

同步和异步通信之间的可用性保证是不同的。基于Kafka流式系统的可用性保证与REST API不同。在流式系统中,我们关注消息处理的吞吐量,而在同步通信中,端到端的延迟是主要关注点(你不希望调用方等待太长时间才能获得结果)。

如果将这两种类型的系统放在一个单一的服务中,就很难评估该服务的可用性。而且,服务的异步部分或同步部分可能会对另一方造成干扰,从而导致服务不可用。

因此,一般建议将基于REST的API和基于Kafka的流式处理作为两个独立的服务。

英文:

Yes, you can definitely write a go service that consumes from Kafka and also exposes a REST endpoint. However, this is not a desirable design decision.

The Kafka-based streaming system allows asynchronous communication between the producer and consumer. However, the REST API-based system does the synchronous communication between the caller and the callee.

The availability guarantee between the sync and sync mode communication is different. The Kafka streaming-based system will have a different availability guarantee than the REST API. In the streaming system, we focus on the throughput of message processing, whereas in the sync communication end-to-end, latency is the main focus (you don't want to keep the caller waiting for a long time to get the result).

If we put both these types of systems in a single service, it becomes difficult to gaze at the availability of the service. Also, the async part or the sync part of the service can play a part in a noisy neighbour for the other side, thus making the service unavailable.

So in general, it is recommended to keep the REST-based API and Kafka streaming as two separate services.

答案2

得分: 0

是的,这是可能的。Kafka Streams Interactive Queries涵盖了这个确切的用例,不过它是在JVM框架中完成的,需要将其移植到Go语言。

英文:

Yes, this is possible. Kafka Streams Interactive Queries covers this exact use case, however, that is all done in JVM Framework, and would need to be ported over to Go.

huangapple
  • 本文由 发表于 2023年3月27日 11:18:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75851866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定