Publish Subscribe Architecture Flashcards
1
Q
What advantage can be realized when using publish subscribe over request response?
A
Request response, even asynchronous has to wait for a response from all the dependent services in a micro services architecture which may result in a delay to the client. Implementing PS reduces the coupling between the services such that the request is handled when services become available and don’t block the original service from sending a successful reply to the client.
2
Q
Advantages
A
- Decouples services and instead publishes to the broker
- Simplifies debugging errors by reducing the points of failure to the broker and not in the exchange of messages between services.
- You have a single contract across the services rather than multiple different messages that need to be created and consumed per services (b/c the original message is just propagated through the system and handled accordingly).
- Guarantees delivery of messages through the architecture because the broker persists messages. A lost transaction guarantee of at least once.
- More salable by allowing for a new service to simply be registered to the broker and doesn’t need any knowledge of the other subscribers to receive the messages.
3
Q
Disadvantages
A
- Can’t use for systems that need to have transactions across services and can result in data consistency issues because all services may not execute in a coordinated manner (i.e. transferring money)
- Can’t guarantee idempotency (i.e. a message causes a service to withdraw money, if it fails and the message is resent more money is withdrawn). Instead it needs a key to compare with to see if money has already been withdrawn and if it has than ignore (this architecture requires application logic to do this).
4
Q
What’s an example of a publish subscriber system?
A
Twitter, post tweets, read tweets in the timeline.