Successfully reported this slideshow.
Your SlideShare is downloading. ×

Message queues

Upcoming SlideShare
Art Of Message Queues
Art Of Message Queues
Loading in …3

Check these out next

1 of 23 Ad

More Related Content

Slideshows for you (20)

Similar to Message queues (20)


Recently uploaded (20)

Message queues

  1. 1. Message Queues The good, the bad… Maksym Bodnar
  2. 2. What is MQ? • MQ (message queue) - is a system that allows two or more processes to interact (communicate) via data exchange: • The code that sends a piece of data (message) and the code that receives that piece of data (message) do not interact directly and (should) know nothing about each other. • A message (usually) is NOT processed at the moment when it is sent. Processing can happen at any moment or can not happen at all. • Edge case: RPC mode, when sender is waiting (blocking the execution) until message is processed.
  3. 3. Key elements: publisher • Publisher (producer) - the app that generates messages and pushes (publishes) them into an MQ.
  4. 4. Key elements: broker (exchange) • Broker (exchange) - the main piece of the MQ architecture, the app that decides how messages are delivered to the consumer. It also provides persistency (if needed), messages acknowledgement and re-delivery (if needed) etc.
  5. 5. Key elements: consumer • Consumer (subscriber) - the part of an app that receives a message from the broker and processes it. Usually this part of application is called “worker” - a script(s) that is waiting for a new message to process.
  6. 6. Key terms: Blocking Blocking means that the code execution is stopped (paused) after making a call or request to a long running service until the service returns a result.
  7. 7. Key terms: Non-blocking Non-blocking execution means that code continues after making a call or request to a long running service and does not wait for the result or output.
  8. 8. Unblock your code
  9. 9. Unblock your code (cnt)
  10. 10. Key benefits of using MQ • Non-blocking code; • Parallel execution; • Easy horizontal scaling; • Use different programming languages; • Application resilience; • Easy requests throttling;
  11. 11. Loops decomposition (parallel execution)
  12. 12. Loops decomposition (parallel execution)(cnt)
  13. 13. Dark side of the MQ • Yet another beast in the zoo; • Bottlenecks; • Integrating with existing code is tricky; • Concurrency issues; • Self blocking queues; • Testing and debugging pain; • Monitoring and maintenance;
  14. 14. Pick your favorite bottleneck • Network interfaces; • CPU/memory load; • DB; • Filesystem; • External services;
  15. 15. Integration (refactoring) can be challenging
  16. 16. Integration (refactoring) can be challenging
  17. 17. Key terms: Synchronous Synchronous execution means execution in the same time line, connected threads. In this case all code in all processes is executed at the same speed and all processes are aware of state of other processes.
  18. 18. Key terms: Asynchronous Asynchronous execution means that all threads or processes are executed independently with no specific order.
  19. 19. Concurrency problem • Be aware of duplicated messages; • Messages are processed in no particular order;
  20. 20. Concurrency problem
  21. 21. Debugging/testing challenges • Automated integration tests are impossible and make little sense; • Response of local vs production environment under load is different; • Debugging is difficult - no united stack tracing available (out of box).
  22. 22. Monitoring • Flood detection (publish/confirm rate); • Self-blocking queues; • Implied Infinite loops; • Messages that are causing exceptions in workers;
  23. 23. Thank you

Editor's Notes

  • 100 orgs x 1000 users x 1s = 100 000 seconds = 28 hours
  • 100 x 1000 x 0.001 = 100 s => 2 min

    10 workers => 10 000 s => 3 hours
    20 workers => 5 000 s => 1.5 hours
  • Key problem here - slow blocking method returns result that is used later.
  • DB transaction makes no sense when decomposing loop to MQ.
    Requires whole concept rethinking.
  • idem·​po·​tent | \ ˈī-dəm-ˌpō-tᵊnt code in workers;

    Code: if each