why actor-based systems are the best for microservices

31
Why actor-based systems are the best for microservices Yaroslav Tkachenko @sap1ens Director of Engineering, Platform at Bench Accounting

Upload: yaroslav-tkachenko

Post on 16-Jan-2017

1.427 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Why actor-based systems are the best for microservices

Why actor-based systems are the best for microservices

Yaroslav Tkachenko@sap1ens

Director of Engineering, Platform at Bench Accounting

Page 2: Why actor-based systems are the best for microservices

Context

Page 3: Why actor-based systems are the best for microservices

Agenda

• Microservices• Messaging for microservices• EIP and messaging• Actors and messages• All combined… and more

Page 4: Why actor-based systems are the best for microservices

Microservices

Page 5: Why actor-based systems are the best for microservices

Microservices

Page 6: Why actor-based systems are the best for microservices

Microservices

Service A Service B

HTTP API / RPC

“Easy” way

Page 7: Why actor-based systems are the best for microservices

Microservices

Challenges with HTTP API / RPC:• Service discovery• Retries for failures • Routing and load balancing• Webhooks• Tracing• Versions• …

Page 8: Why actor-based systems are the best for microservices

Microservices

But…

Page 9: Why actor-based systems are the best for microservices

Messaging for microservices

Page 10: Why actor-based systems are the best for microservices

Messaging for microservices

We should use only messaging for communication between microservices

Page 11: Why actor-based systems are the best for microservices

Messaging for microservices

Reactive Revealed: Resiliency, Failures vs Errors, Isolation, Delegation and Replication by Jonas Boner

Page 12: Why actor-based systems are the best for microservices

Messaging for microservices

Surviving Micro-services by Richard Rodger

Page 13: Why actor-based systems are the best for microservices

Messaging for microservices

Surviving Micro-services by Richard Rodger

Page 14: Why actor-based systems are the best for microservices

EIP and messaging

Page 15: Why actor-based systems are the best for microservices

EIP and messaging

Page 16: Why actor-based systems are the best for microservices

EIP and messaging

EIP was published in 2003 and it contains 65 patterns

Page 17: Why actor-based systems are the best for microservices

EIP and messagingMessage ChannelMessagePipes and FiltersMessage RouterMessage TranslatorMessage EndpointPoint-to-Point ChannelPublish-Subscribe ChannelDatatype ChannelInvalid Message ChannelDead Letter ChannelGuaranteed DeliveryChannel AdapterMessaging BridgeMessage BusCommand MessageDocument MessageEvent MessageRequest-ReplyReturn AddressCorrelation IdentifierMessage SequenceMessage ExpirationFormat IndicatorIntroduction to Message RoutingContent-Based RouterMessage FilterDynamic RouterRecipient ListSplitterAggregator

ResequencerComposed Message ProcessorScatter-GatherRouting SlipProcess ManagerMessage BrokerEnvelope WrapperContent EnricherContent FilterClaim CheckNormalizerCanonical Data ModelMessaging GatewayMessaging MapperTransactional ClientPolling ConsumerEvent-Driven ConsumerCompeting ConsumersMessage DispatcherSelective ConsumerDurable SubscriberIdempotent ReceiverService ActivatorControl BusDetourWire TapMessage HistoryMessage StoreSmart ProxyTest MessageChannel Purger

Page 18: Why actor-based systems are the best for microservices

Actors and messages

Page 19: Why actor-based systems are the best for microservices

Actors and messages

So, I convinced you that messaging patterns are great. Right?

Page 20: Why actor-based systems are the best for microservices

Actors and messages

But why actors? I can just use a message queue and a bunch of consumers/producers

Page 21: Why actor-based systems are the best for microservices

Actors and messages

Sure! But let’s compare

Page 22: Why actor-based systems are the best for microservices

Actors and messages

ActiveMQ message listener in Java

Page 23: Why actor-based systems are the best for microservices

Actors and messages

ActiveMQ message listener in Java (zoom-in)

public class Server implements MessageListener { // … public void onMessage(Message message) { try { TextMessage response = this.session.createTextMessage(); if (message instanceof TextMessage) { TextMessage txtMsg = (TextMessage) message; String messageText = txtMsg.getText(); response.setText(this.messageProtocol.handleProtocolMessage(messageText)); }

response.setJMSCorrelationID(message.getJMSCorrelationID()); this.replyProducer.send(message.getJMSReplyTo(), response); } catch (JMSException e) { } }

// … }

Page 24: Why actor-based systems are the best for microservices

Actors and messages

Actor-based (Akka) message listener in Scala

class CustomerService extends Actor with ActorLogging with Consumer {

val camel = CamelExtension(system)

camel.context.addComponent("activemq", ActiveMQComponent.activeMQComponent( “tcp://localhost:61616” ))

def endpointUri = "activemq:topic:events"

def receive = { case e: CamelMessage => { sender() ! “SomeMessage” } }}

Page 25: Why actor-based systems are the best for microservices

Actors and messages

Btw, some magic is provided by: Apache Camel

“The most unknown coolest library out there”JM

Page 26: Why actor-based systems are the best for microservices

Actors and messages

Actors give you:

• Simple and high-level abstractions for distribution, concurrency and parallelism• Asynchronous, non-blocking and highly performant message-driven

programming model• Very lightweight event-driven processes (several million actors per GB of heap

memory)

Page 27: Why actor-based systems are the best for microservices

Actors and messages

Page 28: Why actor-based systems are the best for microservices

All combined… and more

Page 29: Why actor-based systems are the best for microservices

All combined… and more

Summary:

• It’s easy to build microservices from scratch using messaging patterns• All these patterns are well-known, tested and documented• Actor model gives very simple abstractions to process and send messages• Bonus: all kinds of routing models, back-pressure, reliable queues, broadcasts

Page 30: Why actor-based systems are the best for microservices

Q&A

Page 31: Why actor-based systems are the best for microservices

Reading list

http://microservices.iohttp://www.enterpriseintegrationpatterns.com/patterns/messaging/https://www.amazon.ca/Reactive-Messaging-Patterns-Actor-Model/dp/0133846830 https://www.youtube.com/watch?v=0pfghZxlFSg https://www.youtube.com/watch?v=JvbUF33sKf8 http://akka.io http://camel.apache.org