Should we use bidirectional streaming vs unidirectional grpc requests in a chat app

158 Views Asked by At

I have a simple chat app with an api-gateway responsible for socket.io and chat-microservice responsible for storing chats and messages.

//api-gateway/chat.gateway.ts
//receive web-socket messages here
@SubscribeMessage('sendMessage')
  async handleChatMessage(
    @ConnectedSocket() client: Socket,
    @MessageBody() payload: { roomId: string; text: string },
  ) {
    ....

    //GRPC service. Should i use uni- or bidirectional here?
    await this.chatService.createMessage({
      chatId: Number(roomId),
      userId: user.id,
      text,
    })

    //send messages to web-socket-client
    this.server.to(roomId).emit('sendMessage', {
      userName: user.name,
      userId: user.id,
      text,
    });
  }

Some articles say it's better to do unidirectional requests and that they will work faster and easier to implement. But my employer insists that streams will send messages faster and use less memory. Right now I'm prepare to do benchmarking to check it myself

What will be faster one or another? And what if there will be high loads?

1

There are 1 best solutions below

0
murgatroid99 On

Internally in the gRPC library, all types of requests work the same. A single unidirectional streaming request will have very similar performance to a single bidirectional streaming request. You should focus more on using the type of streaming that corresponds most closely with the semantics of your application.