Event driven microservices

I’ve got lucky I got my spot in last London GOTO conference. Theme was obviously event driven microservices and how they simplify whole architecture of complex applications. After 2 days of listening about them there was no other choice than prototype.

Most intriguing for me was the idea of performing read through event bus as well as writes. It kinda hit me as being against CQS. Couldn’t get why and how. Being in mindset of transactional storage wasn’t helping as well :P

Building event driven microservices

Requirement as simple. One service is providing data and other is requesting and processing it. And some interface to interact with. No need for web, as it’s prototype/proof of concept. Console app it is and Symofny as framework of choice as the simplest way to scaffold code. Yesterday I was thinking about getting kafka but again, I wanted to see results not caring much about technology.

If you want to do system like that in real life please don’t use PHP for that :D

Code you will find here.

So how it works?

I’ve got positively surprised by the effect. Everything was obviously done under a second. Even checking on microsecond level shown loads of time saved in comparison to HTTP.

Think this way – sending order and getting item gives you 2 HTTP calls. It’s not much but with more services interested in this topic it will only grow. And all of it will be done during main order request. So user facing system will be slowed down by every new service attached. Even if response time is about 50ms with only 4 of them it adds 200ms on top of all other processing.

When your microservices communicates with each other with events you’re getting at least three advantages I can think of right now:

  1. No HTTP, less network connections means less time wasted on the wire
  2. Events are asynchronous so if your critical path is finished you can inform end user about it without waiting for all the rest to finish
  3. If one of services in chain fails events will stay in the infrastructure. You’re not loosing any data.  Rest of system is working as normal. Error is atomic to one place. And after it’s fixed you can start processing messages from where it stopped.

Last point is illustrated in my example. When you request non existent item ItemService will fail. Fix collection adding new index and rerun it. Boom. Order gets processed like nothing happened. Just with a bit of delay.

Conclusion

If you can use this pattern it will give you a lot of freedom. Communicating with event bus of any sort will save you a lot of time and money. One thing to do is just to convince your team and company it’s the right thing to do. But it’s topic for another post ;)

Book review: The 21 Irrefutable Laws of Leadership

21irrefutablelawsofleadershipSo I’ve decided to get more in touch with my soft skills. First book I’ve got is The 21 Irrefutable Laws of Leadership. It’s truly great one.

Book

I was quite surprised that book was so easy to read. Every chapter takes less than hour. Each law has story related to it which easily explains how it works in real leadership. It makes it fun to read. Overall great value and if you’re new to leading it will give you quite a lot things to think about and probably change in your life for greater results :)

At the end of the book you can find all the laws with quotes and references to other books for further investigation. It’s nice as this post supposed to be this kind of thing and by second scroll through book I’ve found this appendix with cool stuff.

To keep my online memo you can find list of all leadership laws below.

The Laws of Leadership

  1. The law of the lid
  2. The law of influence
  3. The law of process
  4. The law of navigation
  5. The law of addition
  6. The law of solid ground
  7. The law of respect
  8. The law of intuition
  9. The law of magnetism
  10. The law of connection
  11. The law of inner circle
  12. The law of empowerment
  13. The law of the picture
  14. The law of buy-in
  15. The law of the victory
  16. The law of big Mo[mentum]
  17. The law of priorities
  18. The law of sacrifice
  19. The law of timing
  20. The law of explosive growth
  21. The law of the legacy