Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workers, Queues and Data

Workers, Queues and Data

Designing data flows, queue architectures and reliable worker scripts, using RabbitMQ as the example

Lorna Mitchell

May 09, 2017
Tweet

More Decks by Lorna Mitchell

Other Decks in Technology

Transcript

  1. Introducing Queues Use queues to: • asynchronously process tasks in

    your application • e.g. sending email, processing uploads • provide loose coupling points • e.g. delegate heavy tasks, split ownership/technology • enable parts of the system to scale appropriately • e.g. an event in one system causes a thousand other actions @lornajane
  2. Queue Tools A selection of queue-ish tools • RabbitMQ* http://www.rabbitmq.com/

    • Gearman http://gearman.org/ • Beanstalkd http://kr.github.io/beanstalkd/ • Kafka https://kafka.apache.org/ • Redis https://redis.io/ * RabbitMQ is used in today's examples @lornajane
  3. Framing The Problem • What needs to be done? •

    Is that one task or a series of steps? Turn the steps into a flow diagram @lornajane
  4. Data Hygiene "A swarm of small standalone apps all talking

    to the same database is simply an HTTP-enabled monolith" -- Lorna Mitchell, 2016 @lornajane
  5. Data Hygiene • Where does the data go from? Where

    does the data go to? • How should that data be structured/formatted? • Which component "owns" access to each data store? Add data movement to diagram. Include system inputs/outputs @lornajane
  6. Now really draw the diagram (Then ask another human if

    the naming makes sense) @lornajane
  7. Designing Queues Some vocabulary • exchange: where to send the

    messages to • queue: where messages wait to be processed • message: the data to be processed • binding key: rules for which messages go into this queue • routing key: message route information @lornajane
  8. Designing Queues Queues can: • have wildcards in binding keys

    • be durable (messages have their own durability) • have a maximum length • be configured with a "dead letter exchange" If producer needs feedback, create another queue to put status updates into @lornajane
  9. Expect Failure Sometimes, things go wrong! 1. Decide if you

    care 2. React appropriately Blog post about failure (I'm an expert): http://lrnja.net/rabbitfail @lornajane
  10. Creating Workers Workers are disposable! • if things go wrong,

    exit • separate tool to monitor/restart as needed • beware long-running process hazards • everything processed "at least once" (but maybe more than once, and in any order...) @lornajane
  11. Independent Workers For best results: • awesome, aggregated logging •

    monitoring: queue size, worker uptime, processing time • miniminum viable dependencies @lornajane
  12. Deploying Workers As many workers as you need, per task

    - and this may change Workers can be multi-skilled, one worker for many occasional tasks If in design doubt: more queues @lornajane
  13. Queues in Your Applications Queues are useful in either new

    or existing systems • they introduce resilience • enable migrations/refactoring • improve performance and scalability • (see also: server costs) @lornajane
  14. Resources • Please leave me some feedback! • Try RabbitMQ

    on Bluemix (free trial) http://bluemix.com • Email me: [email protected] • Website: https://lornajane.net Further reading: • Failure handling: http://lrnja.net/rabbitfail • Webhooks example: http://lrnja.net/2iu4iBQ @lornajane