Sitemap
Orhan Yılmaz

Orhan Yılmaz

Full Stack Developer

Queue

2 min readSep 16, 2023

What is a message queue?

Message queue is a form of asynchronous service-to-service communication used in serverless and microservices architectures.

Message queues to process orders and are a way of decoupling different parts of systems.

Similar to database, the queue is a sophisticated piece of software that runs on dedicated hardware.

Why we should use a message queue?

  • Asynchronous communication
  • Prevent transaction loosing
  • Decoupling microservices.

Let's say we have a pizza store and decide to sell online pizza for customers. To do this two microservices were designed pizza and payment services.

Press enter or click to view image in full size
Syncron Communication

So, what happens if our payment service receives too many requests and crashes? Pizza service will also get stuck waiting for payment service to recover.

Get Orhan Yılmaz’s stories in your inbox

Join Medium for free to get updates from this writer.

The solution is a queue mechanism. Let's design a queue mechanism to prevent message stuck and transactions losing.

Press enter or click to view image in full size
Asyncron Communication

And that wat we decouple our fast pizza service from a slow payment service and can process much more orders now!

When a service connects to a queue, it must choose one of two roles. Either can be a producer or a consumer. If consumer crashes, unprocessed message are usually not lost, because they are stored in the queue.

Summary

Pros:

  • Buffering
  • Request spikes smoothing
  • Message durability

Cons:

  • Increase system complexity
  • Increase latency

--

--