26
Distributed Messaging Patterns Cecil L. Phillip Senior Cloud Advocate @ Microsoft @cecilphillip

Distributed Messaging Patterns

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Distributed Messaging Patterns

Distributed Messaging Patterns

Cecil L. Phillip🇦🇬Senior Cloud Advocate @ Microsoft@cecilphillip

Page 2: Distributed Messaging Patterns

Communication

Distribution of messages from one source to anyone

interested

Broadcast

“Radio”

Moving messages between two endpoints.

Direct

“Phone”

Moving messages via communication middleware

Brokered

“Mail”

How do we share information between systems?

Page 3: Distributed Messaging Patterns

Messaging is all about getting data from here to there

(Getting data back from there to here is the just same thing)

A BTransfer

Page 4: Distributed Messaging Patterns

Sometimes there’s a lot of “here”

A BTransfer

A

AA

A

Page 5: Distributed Messaging Patterns

Sometimes there’s A LOT of data

A BTransfer

Page 6: Distributed Messaging Patterns

Sometimes there’s a lot of “there”

A BTransfer

B B

B

B B

Page 7: Distributed Messaging Patterns

Sometimes the “there” are all different

A ETransfer

L L

C

C I

Page 8: Distributed Messaging Patterns

Sometimes “there” isn’t currently paying attention

A BTransfer

Page 9: Distributed Messaging Patterns

Sometimes “there” isn’t currently paying attention

A BTransfer

Page 10: Distributed Messaging Patterns

Sometimes there’s trouble

A BTransfer

Page 11: Distributed Messaging Patterns

Sometimes “there” is VERY BUSY

A BTransfer

Page 12: Distributed Messaging Patterns

Messaging ProtocolsIETF HTTPS & WebSocket Protocol

• Request-response application protocol

• OSS: Nginx, Apache HTTP Server, Kestrel, YARP, Envoy

OASIS AMQP 1.0 • Symmetric, reliable message transfer protocol with support for

multiplexing and flow control

• OSS: Apache ActiveMQ, Apache Qpid Broker-J, Apache Qpid Dispatch Router, Apache Camel, Pivotal RabbitMQ

OASIS MQTT 3.x/5.x• Reliable publish-subscribe protocol for telemetry transfer and state

synchronization

• OSS: Apache ActiveMQ, Eclipse Hono, Pivotal RabbitMQ, Eclipse Mosquitto, HiveMQ, VerneMQ, etc.

Page 13: Distributed Messaging Patterns

Synchronous vs. Asynchronous

ReceiverSender ReceiverSender

• Sender sends request and then waits foran immediate answer

• May happen via asynchronous I/O, but the logical thread is preserved.

• Sender sends a message and proceeds todo other things.

• Replies may flow back on a separate path.

Page 14: Distributed Messaging Patterns

Synchronous Patterns

Page 15: Distributed Messaging Patterns

Throttling

• Request rates can be defined on per-client based on a given criteria

• Throttling state can be communicated via the transport protocol

• Clients should implement an adaptive retry strategy to get their work submitted

ServerClient

Client

Client

Page 16: Distributed Messaging Patterns

Load balancing w/ a Reverse Proxy

• Messages are distributed between multiple servers

• Clients only need direct access access the proxy

• The proxy can be enhanced with additional functionality via middleware

Server

Client

Client

Client

Server

Server

Proxy

Page 17: Distributed Messaging Patterns

Retry Strategies

• Connectivity between systems can unreliable and faults can occur for various reasons

• Use reasonable delays between retries to prevent overloading the system

• Know when to stop retrying

ServerClient

Client

Client

Page 18: Distributed Messaging Patterns

Asynchronous Patterns

Page 19: Distributed Messaging Patterns

Long-Running Work

• Processing at the consumer may take very long (minutes to hours)

• Producers entrust jobs into a queue.

• Bad jobs are moved into a dead-letter queue for inspection.

• Flow back to the producer is performed through a reply queue

ConsumerProducer

correlationid:

reply queue

replyto:

dead-letter queue

Retry 1

Retry 2

Page 20: Distributed Messaging Patterns

Load Leveling

• Queues act as an inbox for requests to a consumer.

• Consumer pulls work when it has capacity for processing.

• Consumers process at their own pace.

• No “too busy” errors, easier resource governance.

Consumer

ProducerProducer

ProducerProducer

Producer

requests/sec

time

requests/sec

time

processing capacity

Page 21: Distributed Messaging Patterns

Load Balancing (and Auto Scaling)

• Multiple consumers compete for messages

• Truly load-aware job balancing

• Queue-length can be observed and more consumers can be added to to manage load

Consumer

ProducerProducer

ProducerProducer

Producer

queue length rolling average

time

scale-up threshold

scale-down threshold +1

ConsumerConsumer

Page 22: Distributed Messaging Patterns

Publish-Subscribe

• Directing one input message to zero or more interested parties (subscribers).

• Every subscriber can obtain a copy of every published message.

• Subscribers may provide filters that select a subset of the published messages.

ConsumerProducer 2 4 6

1 2 3

1 3 5

Topic filter

filter

filter

Consumer

Consumer

Page 23: Distributed Messaging Patterns

Sparse Connectivity

• Common scenario with mobiles devices and IoT applications.

• Mobile users switch networks, go out of range, hit bandwidth caps, etc.

• Using a local store/forward queue makes communication paths more robust.

Consumer

ProducerPush

Pull

store and forward queue

Unreliable network boundary, e.g. mobile wireless networking

move messageswhile online

Page 24: Distributed Messaging Patterns

Recap

Synchronous Asynchronous

ReceiverSender ReceiverSender

Page 25: Distributed Messaging Patterns

https://www.theurlist.com/distributed-messaging-patterns

Samples and Documentation

Page 26: Distributed Messaging Patterns

Thanks and …See you soon!

Thanks also to the sponsors.Without whom this would not have been posible.