{"id":71,"date":"2016-08-30T07:25:52","date_gmt":"2016-08-30T07:25:52","guid":{"rendered":"http:\/\/www.nedlowe.co.uk\/blog\/?p=71"},"modified":"2016-08-30T07:25:52","modified_gmt":"2016-08-30T07:25:52","slug":"class-libraries-with-microservices","status":"publish","type":"post","link":"https:\/\/www.nedlowe.co.uk\/blog\/?p=71","title":{"rendered":"Class Libraries With Microservices"},"content":{"rendered":"<p>Back in the olden days, everyone went nuts for Service Oriented Architecture. \u00a0Many consultant dollars were made. \u00a0Everyone temporarily forgot who Fred Brooks was\u00a0(<a href=\"https:\/\/en.wikipedia.org\/wiki\/No_Silver_Bullet\">No Silver Bullet<\/a>). Time moved on, the hype died down. \u00a0But just like a\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=OcM6PgX-Oc8\">Jeffrey<\/a>\u00a0&#8211; IT COMES BACK. \u00a0Yes, I&#8217;m talking about micro-services.<\/p>\n<p>Martin Fowler has a really nice piece on this topic:\u00a0<a href=\"http:\/\/martinfowler.com\/articles\/microservices.html\">http:\/\/martinfowler.com\/articles\/microservices.html<\/a>\u00a0where he talks about the advantages of being at least familiar with the approach &#8211; especially when designing for cloud-based applications.<\/p>\n<p>With that in mind, having a decentralised, distributed design was important to me as I map out the design for Argomi on the back of\u00a0whatever receipts and envelopes\u00a0I can get my hands on (I look forward to the day when tablets provide me the functionality of pencil and paper). \u00a0However,\u00a0I have now stumbled across a question\u00a0I have previously agonised over: the shared class library.<\/p>\n<p>If we are splitting up a design into pieces, then it seems obvious to want to have a class library shared amongst all services\u00a0with business logic encapsulated and lots of nice code-reuse. The issue comes from the implicit coupling.<\/p>\n<p>One of the &#8216;points&#8217; of microservices is that each service is independent of the others, and can have its own release cycle &#8211; or be completely replaced with an improved version, and the other services don&#8217;t necessarily need to even know. \u00a0This leads to articles like:\u00a0<a href=\"http:\/\/www.simplicityitself.io\/our%20team\/2015\/01\/12\/sharing-code-between-microservices.html\">http:\/\/www.simplicityitself.io\/our%20team\/2015\/01\/12\/sharing-code-between-microservices.html<\/a>\u00a0which suggest not sharing anything &#8211; even class libraries &#8211; since\u00a0changes may require all services to be upgraded at the same time. It also pretty much forces you to use the same technology for all services so that the class library can be shared.<\/p>\n<p>My feeling right now is that avoiding a potential coupling is normally not worth the cost of reimplementing complicated business logic and that one should:<\/p>\n<ul>\n<li>Strive to design fixed interfaces and classes so basic interactions with the class don&#8217;t change over time.<\/li>\n<li>Make changes backwards compatible between versions (e.g. providing a default implementation for a new field) so that the library doesn&#8217;t have to be updated in all services exactly simultaneously, however;<\/li>\n<li>Don&#8217;t allow multiple versions of the library to run for longer than absolutely necessary. \u00a0This is just a modern version of dll-hell, and leads to unnecessary mental load for all developers who need to remember which versions are out in the wild.<\/li>\n<li>For the same reason, unless absolutely necessary never create two\u00a0interface points to the same function, with one simply acting as a pointer\u00a0to the other so that original callers don&#8217;t need to be updated to consume a new interface signature.<\/li>\n<\/ul>\n<p><strong>Does anyone have any alternative experience they would like to share? \u00a0Perhaps a shared class library that got out of control?<\/strong><\/p>\n<p><em>No discussion of microservices would be complete without linking to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fallacies_of_distributed_computing\">the fallacies of distributed computing.<\/a><\/em><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in the olden days, everyone went nuts for Service Oriented Architecture. \u00a0Many consultant dollars were made. \u00a0Everyone temporarily forgot who Fred Brooks was\u00a0(No Silver Bullet). Time moved on, the hype died down. \u00a0But just like a\u00a0Jeffrey\u00a0&#8211; IT COMES BACK. \u00a0Yes, I&#8217;m talking about micro-services. Martin Fowler has a really nice piece on this topic:\u00a0http:\/\/martinfowler.com\/articles\/microservices.html\u00a0where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[6,7],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7QqxF-19","jetpack-related-posts":[{"id":64,"url":"https:\/\/www.nedlowe.co.uk\/blog\/?p=64","url_meta":{"origin":71,"position":0},"title":"AngularFire 2.x.x","date":"August 4, 2016","format":false,"excerpt":"I recently struggled a little to find good documentation on AngularFire 2.x.x - basically the version post when Google bought out FireBase. \u00a0If you search for Firebase and AngularJS, or even if you go to http:\/\/angularfire.com, it all goes to the older version. However, there is some fairly good documentation\u2026","rel":"","context":"In \"angular\"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12,"url":"https:\/\/www.nedlowe.co.uk\/blog\/?p=12","url_meta":{"origin":71,"position":1},"title":"Persisting a Collection with an arbitrary enum type","date":"January 2, 2014","format":false,"excerpt":"(Recovered from my old Blog). As we know, enums are great for storing (relatively) static domain information. But let\u2019s say we want an object which models (and can persist) a collection of elements where we are not sure at design time which domain information will be stored. For example, a\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/71"}],"collection":[{"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=71"}],"version-history":[{"count":4,"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":75,"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/71\/revisions\/75"}],"wp:attachment":[{"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nedlowe.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}