전체 페이지뷰

2015년 5월 21일 목요일

micro service Architecture

http://www.slideshare.net/MarcinGrzejszczak/4finance-microservices-122014-at-lodz-jug
http://www.javaadvent.com/2014/12/doing-microservices-with-micro-infra.html


Is monolith bad?

No it isn't! The most important thing to remember when starting with microservices is that it will complicate your life in terms of operations, metrics, deployment and testing. Of course it does bring plenty of benefits but if you are unsure of what to pick - monolith or microservices then my advice to use is to go the monolith way.

All the benefits of microservices like code autonomy, doing one thing well, getting ridd of pacakge dependencies can be also achieved in the monolithic code thus try to write your applications with such approaches and your life will get simpler for sure. How to achieve that? That's complicated but here are a couple of hints that I can give you:
  • try to do DDD. No, you don't have DDD when your entities have methods. Try to use concepts of aggregate roots
  • try not to make dependencies on packages from different roots. If you have two different bounded context like com.blogspot.toomuchcoding.client andcom.blogspot.toomuchcoding.loan - go via tight cohesion and low coupling - emit events, call REST endpoint, send JMS messages or talk via strictly defined API. Do not reuse internals of those packages - take a look at the next point that deals with encapsulation
  • take your highscool notes and read about encapsulation again. Most of us make the mistake of thinking that if we make a field private and add an accessor to it then we have encapsulation. That's not true! I really like the example of Slawek Sobotka (article in polish) who shows an example of common approach to encapsulation:

    human.getStomach().getBowls().getContent().add(new Sausage())

    instead of

    human.eat(new Sausauge())
  • add to your IDE class generation template that you want your new classes to be package scoped by default - what should be publicly available are interfaces and really limited number of classes
  • start doing what's crucial in terms of tracking microservice requests and measuring business and technical data in your own application! Gather metrics, set up correlation ids for your messages, add service discovery if you have multiple monoliths.

I'm a hipster - I want microservices!

Let's assume that you know what you are doing, you evaluated all pros and cons and you want to go down the microservice way. You have a devops culture there in your company and people are eager to start working on multiple codebases. How to start? Pick our tools and you won't regret it ;)

Clone a repo and get to work

We have set up a working template on Github with UI - boot-microservice-gui and without it - boot-microservice. If you clone our repo and start working with it you get a service that:
  • uses micro-infra-spring library
  • is written in Groovy
  • uses Spring Boot
  • is built with Gradle (set up for 4finance - but that's really easy to change)
  • is JDK8 compliant
  • contains an example of a business scenario
what you just have to do is:
  • check out the slides above to see our approach to microservices
  • remove the packages com/ofg/twitter from src/main and src/test
  • alter microservice.json to support your requirements
  • write your code!
Why should you use our repo?
  • you don't have to set up anything - we've already done it for you
  • the time required to start developing a feature is close to zero

Aren't we duplicating Spring Cloud?

In fact we're not. We're using it in our libraries ourselves (right now for property storage in Git repository). We have some different approaches to service discovery for instance but in general we are extending Spring Cloud's features by:

Conclusions

If you want to go down the microservice way you have to be well aware of the issues related to that approach. If you know what you're doing you can use our libraries and our microservice templates to have a fast start into feature development. 

댓글 없음:

댓글 쓰기