-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.xml
More file actions
1742 lines (1363 loc) · 219 KB
/
feed.xml
File metadata and controls
1742 lines (1363 loc) · 219 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2021-03-14T16:50:55+01:00</updated><id>http://localhost:4000/feed.xml</id><title type="html">Steve Hostettler</title><subtitle>Steve Hostettler's personal blog about automatic testing, Java, Java EE, and Architecture.</subtitle><entry><title type="html">Microservice Architecture - Part 3 (Diving into microservices)</title><link href="http://localhost:4000/2019/03/04/microservice-architecture-part-3.html" rel="alternate" type="text/html" title="Microservice Architecture - Part 3 (Diving into microservices)" /><published>2019-03-04T22:51:20+01:00</published><updated>2019-03-04T22:51:20+01:00</updated><id>http://localhost:4000/2019/03/04/microservice-architecture-part-3</id><content type="html" xml:base="http://localhost:4000/2019/03/04/microservice-architecture-part-3.html"><h2 id="introduction">Introduction</h2>
<p>In <a href="https://www.hostettler.net/2019/02/17/microservice-architecture-part-1.html">Part 1</a>, we configured, compiled, and deployed microservices. In <a href="https://www.hostettler.net/2019/02/17/microservice-architecture-part-2.html">Part 2</a>, we configured and deployed non-functional services such
as security, and logging.
In this chapter, we will dive into the concept of microservices. First, we will discuss why the community came with yet another architecture paradigm. Secondly, we will
look at some definitions and the main properties of such an architecture. Then we will detail some of the technologies, microservice architecture leverage to deliver maximum value.
After that, we will analyse the pros and cons of this architecture. Finally, we will discuss some of the architecture patterns related to microservices.</p>
<h2 id="why-yet-another-architecture-paradigm">Why (yet) another architecture paradigm</h2>
<p>The microservice architecture can be seen as a reaction to the <a href="https://en.wikipedia.org/wiki/Monolithic_application">monolith architecture</a>. In particular, the fact that the bigger the application, the slower the pace of change.
A monolith application is self-contained. Modules mostly communicate through method calls. While monolith do present some advantages in terms of performance
(not scalability) and consistency for instance, they have a tendency to evolve to complex “thing” that run out of control.
Modifying a monolith requires to
rebuilt it completely and to ship it in one block. Furthermore, by its very nature, a monolith tend to favor API leaks and to decrease modularity.
Finally, having one block means that scalability happens at
that granularity which might lead to a waste of resources as all the modules will be scaled at the same time whereas not all the modules might
need the same type of scalability or no scalability at all.</p>
<p>Following the model provided by M. L. ABBOTT and M.T. FISHER [1], scalability follows three dimensions:</p>
<ol>
<li>X-axis : horizontal duplication</li>
<li>Y-axis : functional decomposition</li>
<li>Z-axis : data partitioning</li>
</ol>
<p>While X and Z scalability is feasible with a monolith, Y (functional) scalability is not. It is all or nothing.</p>
<p>The below figure presents a typical monolith architecture. Please note that,</p>
<ul>
<li>usually a monolith is implemented as a multi-tiers architecture</li>
<li>monolith does not mean that it is not modular. It means that it is a “monolithic” unit of deployment. Everything is deployed together.</li>
<li>cross-cutting concerns at shared and the monolith instance level</li>
<li>inter service (modules) communication is usually method calls (vs inter process communication)</li>
<li>scalability happens at the monolith level</li>
</ul>
<figure class="image"><pre>
<img src="/figures/Monolith.png" alt="Monolith architecture" />
<figcaption>Monolith architecture</figcaption>
</pre>
</figure>
<p>Breaking the monolith apart in small pieces, enables to make architectural decision at that level. For instance, to choose the most appropriate programming language or technology
for each task. That being said adding heterogeneity and increasing the number of deployment units,
comes at a price in terms of necessary infrastructure and thus complexity.</p>
<h2 id="definitions">Definition(s)</h2>
<p>At this core, microservice is an architecture (MSA) that is an evolution of the service oriented architecture (SOA). It inherits from SOA several key concepts. The most important one being
that business added value is delivered by combining a collection loosely coupled services.</p>
<p>Reusing the definition of services from SOA, a service has the <a href="https://en.wikipedia.org/wiki/Service-oriented_architecture">following properties</a>:</p>
<ul>
<li>It logically represents a business activity with a specified outcome.</li>
<li>It is self-contained.</li>
<li>It is a black box for its consumers (and the communication between consumer and provider is formalized by a contract).</li>
<li>It may consist of other underlying services.</li>
</ul>
<p>These properties apply to microservices as well. The main difference between SOA and MSA is in the granularity of the services and some opinionated implementation choices.
A key point to understand is that microservices have not been invented in isolation, they emerged alongside other game changers
such as Agile, DevOps concepts, and Cloud computing.</p>
<p>Adding these influences to the mix, adds the following properties:</p>
<ul>
<li>each service is expected be elastic (horizontal scalability), resilient (failover), composible, minimum, and self-contained.</li>
<li>each services must support automation, deployment, and testing as first class citizens.</li>
<li>each is specialized in one thing and in doing that thing right</li>
</ul>
<p>The term microservice has been coined around 2012 [2][3]. People trace it back to a workshop in Venice in 2011 but I was not able to find the proceedings.</p>
<figure class="image"><pre>
<img src="/figures/microservices.PNG" alt="Microservice architecture" />
<figcaption>Microservice architecture</figcaption>
</pre>
</figure>
<h2 id="technologies">Technologies</h2>
<p>Two main technologies are usually linked to microservices:</p>
<h4 id="cloud-native-technologies">Cloud native technologies</h4>
<p>Due to their distributed nature, Microservices call for a distributed way of deploying and management. Therefore, they are inherently linked to cloud native technologies such as containers and containers orchestration.
As a matter of fact, without these technologies developing, building and deploying a microservice architecture would be so tedious and cumbersome that it would
quickly collapse under its own weight.</p>
<p>Docker and <a href="https://kubernetes.io/">Kubernetes</a> bring the ease of deployment and management that is required to deal with hundreds of units. You can see as Kubernetes as the Operating
System of the cloud and as Docker as the process of the cloud.
Thanks to Docker, developer do not have to deal with OS/platform specific configurations. If it works in the container (mostly Linux) it
will work in the cloud. Configuration can be scripted so the deployment is repeatable and automated. In association with Kubernetes, one can
easily manages the elasticity, and health of the microservice ecosystem. Not to mention that a number of 3rd party tools are
available as images that can be composed at will to provide crucial services such as logging, authentication, authorization, and monitoring.</p>
<h4 id="message-broker">Message broker</h4>
<p>Another technology often associated with microservices is the message broker. <a href="https://en.wikipedia.org/wiki/Message_broker">Message Brokers</a> are basically bus that can exchange messages at
a very high speed in a distributed and elastic way. At the moment, <a href="https://kafka.apache.org/">Kafka</a> is the most well-known of these. It is very often as a communication
layer between the microservices. Kafka helps dealing with maintaining consistency by propagating messages in a asynchronous and transactional way.
Message brokers are not a new concepts and they can be associated with the good old Enterprise Service Buses (ESB) of the Service Oriented Architecture era.
The main difference is that, in order to avoid the <a href="https://www.thoughtworks.com/radar/techniques/recreating-esb-antipatterns-with-kafka">ESB antipattern</a>, message broker adopt a more lightweight approach. The big selling
arguments around ESBs was that they would allow proper composition, discovery, and monitoring of the services as well as message and protocol transformation.
The problem was that, at the end, all the business logic of the company was contained in the bus and thus it was extremely difficult to maintain.
Microservices over Message Brokers take a more decentralized approach by letting the responsibility of the transformation, and composition to microservices.</p>
<h2 id="additional-properties-of-microservices">Additional properties of microservices</h2>
<p>Some of the properties of microservices are not inherited from the definition but rather from some implementation decisions.
Please note that some of these properties might sound counter intuitive at first but they emerged to solve practical problems. Especially to limit service coupling.</p>
<h4 id="single-database-per-service">Single Database per service</h4>
<p>Sharing databases across multiple microservices increases coupling. Changing a database model for one service might impact other services. Furthermore, depending of the usage
you might prefer a good old database or a key-value store. Having one database per service solves these problems at the expense of maintaining more technologies, instances and models.</p>
<h4 id="low-cross-service-reuse">Low cross-service reuse</h4>
<p>This is, in my opinion, the most counter-intuitive thing. We have been told for years to reuse and to not duplicate code. And here it is, code duplications is promoted. More specifically
the best practices is to not create “common” libraries. I would not be so “extreme” and simply say not to create common libraries with shared business code (for instance NO DTO).</p>
<h4 id="one-domain-per-service">One Domain per service</h4>
<p>This is the most intuitive of the rules, restrict your micro services to deal with one and only one business domain. For instance, do not mix services for sales and for accounting.
If within accounting, you have two accounting standards, then let’s have two services.</p>
<h4 id="service-granularity">Service Granularity</h4>
<p>Choosing the right granularity for your services is more an art than a science. There are numerous articles out there to help you choose the right granularity [4] [5].
Finding the right level of granularity is usually a tradeoff between thus between maintainability and scalability on one hand, and deployment complexity and performance on the other hand.
It is always a choice between maintainability at the micro level (the service) and the macro level (the whole ecosystem).</p>
<p>Although it is difficult to predict the actual penalty of microservices on the performance as it depends of the use case, [5] predicts a 10% penalty per hops (microservice to microservice communication) on the total roundtrip.
I like the <a href="https://cloudsourceblog.com/2017/01/03/cooking-breakfast-and-microservice-granularity/">breakfast example</a> where a single macro service called <code class="highlighter-rouge">prepare breakfast</code> ends up being 3, 12, or 60 services depending of the level
of granularity. Now imagine, we need to scale the 60 services to have … say 3 instances. All of a sudden you have 180 instances to maintain and to manage. This is becoming exponentially more complex.
In that example, the right level is probably 12 as it proposes some valuable reuse and still limit the complexity.
That being said, nothing stops you to have different level of granularity per domain depending of the expected evolutivity, reuse, and performance. As a rule it is better to start with coarser services and to go granular on a case by case basis.</p>
<p>There are recommendations out there that a microservice should between 50 to 500 lines of codes. This is, in my opinion, the worst possible metric out there. It is way too dependent of the language and technology.</p>
<p>The most important rule about the granularity is to respect the service boundaries:</p>
<ul>
<li>It doesn’t share database tables with another service.</li>
<li>It has a minimal amount of business entities,</li>
<li>It is stateless (and if stateful it is on purpose).</li>
<li>It does take data (un)availability into accounts. For instance by implementing local caches for non-managed entities.</li>
<li>It is the single source of truth for the business entities it manages.</li>
</ul>
<h2 id="architecture-patterns">Architecture patterns</h2>
<h4 id="command-query-responsibility-segregation-cqrs">Command Query Responsibility Segregation (CQRS)</h4>
<p>Command Query Responsability Segregation is all about … guess what … reducing coupling. The idea is to have a different API for querying data and for creating/updating them.
At its core, it seggregates the model and the storage to query data from the model and storage that keeps the single version of truth of a particular business entity.
The two APIs can be part of the same microservice or in two different microservices. One use case to have it on two separate microservices is to be able to scale out querying (or vice versa).</p>
<p>As each microservice can have its own store, then you could imagine using Cassandra (which is known to be very efficient in writing) for persisting and Elasticseach for read (which is known to be very efficient in reading).
Command and Query Responsibility Segregation (CQRS) was first introduced by Greg Young [6] and is itself an evolution of the Command Query Separation (CQS) by Bertrand Meyer [7]</p>
<p>In the sample architecture, the instrument service has one view of the instrument model but the valuation service as another one. To be fully CQRS compliant, the instrument service should have
had a different model to persist and to query. As JPA does not support two entities on the same database object, we would have to use a constructs like JPA queries and <code class="highlighter-rouge">select new</code> to support a
different model for persistence and for reading. For more information on how to use the select new``, please refer to this <a href="https://vladmihalcea.com/the-best-way-to-map-a-projection-query-to-a-dto-with-jpa-and-hibernate/">article</a>
and this <a href="https://www.oracle.com/technetwork/articles/vasiliev-jpql-087123.html">article</a>.</p>
<p>CQRS is very associated with Event sourcing (see below).</p>
<figure class="image"><pre>
<img src="/figures/CQRS_EventSourcing.png" alt="CQRS + Event Sourcing architecture" />
<figcaption>CQRS + Event Sourcing architecture</figcaption>
</pre>
</figure>
<h4 id="event-sourcing--message-bus">Event sourcing &amp; Message Bus</h4>
<p>In an architecture where neither the data store nor the data model is supposed to be shared, keeping the consistency between the different stakeholders is challenging. Having distributed transactions that span
across multiple services is difficult to implement and even more difficult to maintain. That is why, instead of looking for consistency at any point in time, we are looking at eventual consistency.
Of course, eventual consistency might be a problem in some use cases and that must be assessed on a case by case basis.</p>
<p>The fundamental concept behind Event Sourcing is that <code class="highlighter-rouge">All changes to an application state are stored as a sequence of events</code> [8]. In other terms, changing the value of a given field for a given entity is stored as a message.
Ultimately, you can reconstruct the current state by replaying all the messages starting with the initial state.</p>
<p>In the sample architecture (see below), the instrument service is writing any changes to a message broker that is distributed to all microservices that need it. In this case, to
the valuation service and to the regulatory reporting service. Instrument service has the single version of the truth and all other service will eventually be consistent. Of course, internally the instrument service
must guarantee that updating its own store and the bus is made transactionally.</p>
<p>Since the changes are stored in the bus, they can be replayed. For instance, when a new instance of a service joins so that it can update its internal state.</p>
<h4 id="api-composition--api-gateway">API Composition / API Gateway</h4>
<p>As we already discussed, non-functional concerns such as load-balancing, versioning, security (authentication, authorization, TLS termination) must be managed at the microservice level.</p>
<p>Furthermore, maximizing microservice reusability implies granular services. The client could easily compose the microservices but this means a high coupling between the client and the
services as well as a lot of traffic between the client and the microservices.</p>
<p>One way of mitigating this, is to add an API gateway in front of the microservices to avoid direct coupling between the client and the individual services. Besides, it will handle composition
locally in the application network. Finally, it will apply cross-cutting concerns uniformally on all the requests.</p>
<p>The sample application relies on an application gateway to deliver authentication, versioning and TLS termination (see figure below)</p>
<figure class="image"><pre>
<img src="/figures/micro-service-architecture.png" alt="Network topology and high level component view of the micro-service architecture" />
<figcaption>Network topology and high level component view of the micro-service architecture</figcaption>
</pre>
</figure>
<h2 id="pros-and-cons">Pros and Cons</h2>
<p>Let’s reflect on the pros and cons of the microservice architecture. Like any architecture, it is a tradeoff between a set of non-functional requirements.</p>
<h3 id="pros">Pros</h3>
<p>Fist the positive aspects</p>
<h4 id="scalability">Scalability,</h4>
<p>Scalability (both horizontal and vertical) can happen a very granular level. Therefore, no resources are wasted on scaling components that do not require it (like it would be the case
for a monolith). Furthermore, because it is easy to segregate stateful from stateless components, scalability happens most of the time on pure stateless microservices.
In a monolith, one stateful component forces the whole monolith scalability to take stafulness into account.</p>
<h4 id="failover-fault-tolerance-high-availability">Failover, Fault Tolerance, High-Availability</h4>
<p>In a very similar way to scalability, Failover, Fault Tolerance, and High-Availability can be targeted to the components that require it. Similarly,
statefulness can be limited to the few services that require it (if any).</p>
<h4 id="time-to-market-adaptability">Time to market, Adaptability</h4>
<p>Because the services are small and loosely coupled, they can be changed and deployed with limited risk of regression to other services. This increases time to market and is
a big step forward continuous delivery.</p>
<h4 id="team-independence">Team Independence</h4>
<p>Similarly to the time to market, the loose couple implies low inter-team dependency. That being said, this is sort of by product to the microservice architecture.
A modular monolith should in theory achieve the same level of loose coupling. The problem is that when calls internal (rather than through the network), developer have
a higher tendency to break module boundaries thus increasing the coupling.</p>
<h4 id="technology-adaptability">Technology Adaptability</h4>
<p>Again, loose coupling and low dependency enact new practices such as deciding which technology to choose on the case by case basis. That being said, depending of your organization,
this can be more of a curse than a blessing. You can very quickly end up with exotic technologies and languages that only the microservice creator knows.</p>
<h4 id="reusability">Reusability</h4>
<p>Thanks to the granularity, services are much more dedicated to a particular task. This is favoring reusability by composition.</p>
<h3 id="cons">Cons</h3>
<p>Like any architecture, there is no free lunch:</p>
<h4 id="increased-resource-consumption">Increased resource consumption</h4>
<p>As a microservice architecture entails many more instances (e.g., VMs, JVMs) to run that its monolithic counterpart. Furthermore, entities are very often replicated between the instances (to increase loose coupling).
All of that lead to higher overall resources (memory and CPU) consumption. This is compensated by the fact that more resources are available than years ago before the cloud era.</p>
<h4 id="operational-overhead--deployment-complexity">Operational Overhead / Deployment complexity</h4>
<p>The profusion of services and their associated dependencies (DB, message broker, …) can very quickly lead to an operational nightmare. The operation team needs to master the concepts
and the related tools for monitoring the ecosystem (Docker, Kubernetes, ELK, …). This has a cost, both in terms of skills and manpower.</p>
<h4 id="cross-cutting-concerns">Cross-Cutting concerns</h4>
<p>Since the cross-cutting concerns are managed at the service level, it can significantly complexify deployment : a microservice might be straightforward but let’s add it authentication,
authorization, logging, versioning, failover, balancing and it is a completely different story. Doing system testing on such environments can be very challenging.</p>
<h4 id="architecture-complexity--distributed-system">Architecture Complexity : Distributed system</h4>
<p>Microservices are distributed by nature and thus exposes developers to <a href="https://www.rgoarchitects.com/Files/fallacies.pdf">“The 8 fallacies of distributed computing”</a> :</p>
<ol>
<li>The network is reliable.</li>
<li>Latency is zero.</li>
<li>Bandwidth is infinite.</li>
<li>The network is secure.</li>
<li>Topology doesn’t change.</li>
<li>There is one administrator.</li>
<li>Transport cost is zero.</li>
<li>The network is homogeneous.</li>
</ol>
<p>When designing your microservice architecture, you will have to think of all of the above. Another interesting law to remember is the [9] :</p>
<blockquote>
<p>Fowler’s first law of distributed computing : don’t distribute your objects</p>
</blockquote>
<p>While Fowler’s rightfully insists in a this <a href="https://www.martinfowler.com/articles/distributed-objects-microservices.html">post</a> that there is a huge difference between distributing objects and (micro) services. Therefore,
he underlines that his 2004 comment is not in any way applicable to microservice architecture. Although I agree that the two are very different, I think that it is interesting
to look at his entire <a href="http://www.drdobbs.com/errant-architectures/184414966">chapter</a> that is available online. Before laying down the law, Fowler spend some time explaining how he came to that
conclusion. Most of the argument is that not choosing the granularity of the interfaces (API) will lead to poor performance and will massively increase complexity. This is also
very true for microservices.</p>
<p>While there are architecture patterns and tools to deal with them, it just means extra-complexity
and therefore you should ask yourself where it does and where it does not make sense.</p>
<h4 id="eventual-consistency">Eventual consistency</h4>
<p>Hereafter a summary of the main “pros” and “cons”. Please note that this is not an absolute evaluation. The weight that you should put in each of these is highly dependent of
your use-case and context. For instance, team independence is not a real concern in a small startup with 5 employees. On the other end, operation complexity tends to be less
of a problem if you already have skilled devops teams.</p>
<p><br /></p>
<table>
<thead>
<tr>
<th style="text-align: left">Property</th>
<th style="text-align: center">Microservice</th>
<th style="text-align: center">Monolith</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">Scalability</td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
</tr>
<tr>
<td style="text-align: left">Release/Updatability, Time to marker</td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
</tr>
<tr>
<td style="text-align: left">Failover, Fault Tolerance, High Availability</td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
</tr>
<tr>
<td style="text-align: left">Team Independence</td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
</tr>
<tr>
<td style="text-align: left">Technology Adaptability</td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
</tr>
<tr>
<td style="text-align: left">Reusability</td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
</tr>
<tr>
<td style="text-align: left">Resources Consumption (like for like for a given throuput/volume)</td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
</tr>
<tr>
<td style="text-align: left">Operational Overhead</td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
</tr>
<tr>
<td style="text-align: left">Cross-Cutting Concerns (Security, Logging, Caching, Auditing, Configuration, …)</td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
</tr>
<tr>
<td style="text-align: left">Architecture complexity (Distribution, Consistency, Governance, Integration testing, …)</td>
<td style="text-align: center"><span class="table-grade-minus">-</span></td>
<td style="text-align: center"><span class="table-grade-plus">+</span></td>
</tr>
</tbody>
</table>
<h2 id="closing-thoughts">Closing Thoughts</h2>
<p>To sum it up : whereas microservice architecture is a powerful tool in your toolbox, it is in no way a silver bullet. Microservice architecture is very adapted when a high level of elasticity is required but
it comes at a price in terms of complexity of operations. Architecture is always a tradeoff between non-functional requirements and therefore the first thing to do is to establish these NFRs.
If scalability and updatability is not an issue then having a modular monolith is probably more appropriate. Furthermore, there is nothing stopping you to adopt a hybrid approach by
starting to break a monolith in coarse services and to refine it as needed.</p>
<h2 id="bibliography">Bibliography</h2>
<ul>
<li>[1] Martin L. Abbott and Michael T. Fisher. 2009. The Art of Scalability: Scalable Web Architecture, Processes, and Organizations for the Modern Enterprise (1st ed.). Addison-Wesley Professional.</li>
<li>[2] James Lewis. 2013. Micro services - Java, the Unix Way. 33rd Degree Conference, Krakow Poland. http://2012.33degree.org/talk/show/67</li>
<li>[3] Fred George. 2013. MicroService Architecture, https://www.slideshare.net/fredgeorge/micro-service-architecure</li>
<li>[4] Chistian Verstraete, 2017, https://cloudsourceblog.com/2017/01/03/cooking-breakfast-and-microservice-granularity/</li>
<li>[5] Shadija, D., Rezai, M., &amp; Hill, R. (2017). Microservices: Granularity vs. Performance. In UCC 2017 Companion - Companion Proceedings of the 10th International Conference on Utility and Cloud Computing (pp. 215-220). Association for Computing Machinery, Inc. https://doi.org/10.1145/3147234.3148093</li>
<li>[6] Greg Young, 2010. CQRS Documents. https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf</li>
<li>[7] Bertrand Meyer. 1988. Object-Oriented Software Construction (1st ed.). Prentice-Hall, Inc., Upper Saddle River, NJ, USA.</li>
<li>[8] Martin Fowler, 2005, Event Sourcing : https://martinfowler.com/eaaDev/EventSourcing.html</li>
<li>[9] Martin Fowler. 2002. Patterns of Enterprise Application Architecture. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.</li>
</ul></content><author><name></name></author><summary type="html">Introduction In Part 1, we configured, compiled, and deployed microservices. In Part 2, we configured and deployed non-functional services such as security, and logging. In this chapter, we will dive into the concept of microservices. First, we will discuss why the community came with yet another architecture paradigm. Secondly, we will look at some definitions and the main properties of such an architecture. Then we will detail some of the technologies, microservice architecture leverage to deliver maximum value. After that, we will analyse the pros and cons of this architecture. Finally, we will discuss some of the architecture patterns related to microservices.</summary></entry><entry><title type="html">Microservice Architecture - Part 1 (A running microservice architecture)</title><link href="http://localhost:4000/2019/02/17/microservice-architecture-part-1.html" rel="alternate" type="text/html" title="Microservice Architecture - Part 1 (A running microservice architecture)" /><published>2019-02-17T22:51:20+01:00</published><updated>2019-02-17T22:51:20+01:00</updated><id>http://localhost:4000/2019/02/17/microservice-architecture-part-1</id><content type="html" xml:base="http://localhost:4000/2019/02/17/microservice-architecture-part-1.html"><h2 id="introduction">Introduction</h2>
<p>This series of blog posts aims at helping students at the University of Geneva to develop their first application following micro-service principles.
Besides explaining the concepts and implementation details of micro-service architecture, we will as well discuss software development practices such as software
factories and innovative deployment options such as containers and container composition. All samples and a complete working application can be found <a href="https://github.com/hostettler/microservices.git">here on GitHub</a></p>
<p>The following diagram represents the end-state of our microservice architecture. From a business perspective, it delivers <a href="https://en.wikipedia.org/wiki/Regulatory_technology">RegTech</a> services.
More specifically, it manages counterparties and financial instruments. It valuates a portfolio and finally provides some regulatory reporting.
You do not need deep financial knowledge, sufficient is to say that:</p>
<ul>
<li>A counterparty is an individual or a company participating in a financial transaction. For more <a href="https://www.investopedia.com/terms/c/counterparty.asp">details</a>.</li>
<li>A financial instrument is an asset that can be traded such as stocks, loans, and the likes. For more <a href="https://www.investopedia.com/terms/f/financialinstrument.asp">details</a>.</li>
<li>Portfolio valuation is the action of evaluating the net value of a set of assets. For more <a href="https://www.investopedia.com/terms/a/assetvaluation.asp">details</a>.</li>
<li>Financial institutions must comply to a set of regulations such as delivering monthly reports to state their financial health.</li>
</ul>
<figure class="image"><pre>
<img src="/figures/micro-service-architecture.png" alt="Network topology and high level component view of the micro-service architecture" />
<figcaption>Network topology and high level component view of the micro-service architecture</figcaption>
</pre>
</figure>
<p>Besides, these “business” services, the architecture delivers a set of non-functional services such as:</p>
<ul>
<li>A Central logging mechanism to deal with the distributed nature of the architecture. It relies on a <a href="https://github.com/gliderlabs/logspout">Logspout</a> companion container that sends the logs from all the containers to a concentrator called <a href="https://www.elastic.co">Logstash</a> that in turn
sends them to a database optimized for searching called <a href="https://www.elastic.co">ElasticSearch</a>. Finally, <a href="https://www.elastic.co">Kibana</a> provides visualization and analysis of the logs.</li>
<li>A Message broker to increase service decoupling and scalability. <a href="https://kafka.apache.org/">Kafka</a> in this case.</li>
<li>An API-Gateway that provides routing, load-balancing and SSO to the micro-services by integrating an identity manager called <a href="https://www.keycloak.org/">Keycloack</a>. Furthermore, <a href="https://konghq.com/kong/">Kong</a> delivers API-Gateway services (e.g., security, API composition and aggregation)
The API-Gateway also shields the user from knowing the ugly details of the network topology. Furthermore, it protects the backend by establishing a clear front vs back network separation,
it exposes static resources and finally, it provides TLS termination.</li>
</ul>
<p>From a technology perspective, Microservices are implemented using JEE 8 microservice and its microprofile. More specifically, <a href="https://thorntail.io/">Thorntail</a> [3].
Furthermore, microservices are packaged as <a href="https://www.docker.com/">Docker</a> [1][2] container using <a href="https://maven.apache.org/">Maven</a> [4] as a build tool.</p>
<p>This chapter describes step by step how to compile and deploy the microservices themselves.
<a href="https://www.hostettler.net/2019/02/17/microservice-architecture-part-2.html">Part 2</a> describes how to setup non-functional services such as SSO (Single Sign On), API concentration, and logging. Because of its
distributed nature, in
a microservice architecture, the non-functional infrastructure is as important than the actual services.
<a href="https://www.hostettler.net/2019/03/04/microservice-architecture-part-3.html">Part 3</a> dives deeper in what a microservice architecture actually is, its benefits and drawbacks, and some details on the related technologies.
Part 4 focuses on the software factory, putting everything together and testing the result.
Finally, Part 5 does the autopsy of a microservice, detailing the associated design patterns.</p>
<h1 id="pre-requisites">Pre-requisites</h1>
<div class="alert alert-info" role="alert"><i class="fa fa-info-circle"></i> <b>Note: </b> This series of blog post leverages a lot of different technologies. Please take the time to install everything properly. It will save time later on. </div>
<p>To execute the samples, you will need to install and to configure the following tools:</p>
<ul>
<li>a “reasonably” powerful computer with Linux (whatever recent distribution) or Windows (min. Windows 10) to support Docker. Mac is ok as well, but it requires some additional steps that will not be described here.</li>
<li>a working Docker environment to deploy the services locally.</li>
<li>a <a href="https://jdk.java.net/11/">JDK 11</a> to compile and run the services</li>
<li>a Git client for collaboration</li>
<li><a href="https://nodejs.org/">NodeJS</a> and the <a href="https://angular.io/guide/quickstart">Angular tooling</a></li>
<li><a href="https://maven.apache.org/">Apache Maven</a> for the automation.</li>
<li>a bash interpreter (on Windows you can rely on Git bash that is usually installed with Git)</li>
</ul>
<p>On top of that you need to have:</p>
<ul>
<li>An intermediate level in Java</li>
<li>Some basic understanding of OS (including bash scripting) and networking (DNS, TCP, HTTP)</li>
<li>a great deal of patience and coffee</li>
</ul>
<div class="alert alert-info" role="alert"><i class="fa fa-info-circle"></i> <b>Note: </b> We will start a lot of containers, please grant at least 6GB RAM and 6GB swap to your docker-machine </div>
<h2 id="getting-the-backend-components-to-run">Getting the backend components to run</h2>
<p>First things first, let’s checkout the code and compile everything. Before you start complaining,
yes, this section is tedious but we have to have the environment set up before diving into the wonderful world of microservices.
Let’s start by cloning the code from <a href="https://github.com/hostettler/microservices.git">GitHub</a>.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>git clone https://github.com/hostettler/microservices.git</code></pre></figure>
<figure class="console-output"><pre class="console-output">
Cloning into 'microservices'...
remote: Enumerating objects: 875, done.
remote: Counting objects: 100% (875/875), done.
remote: Compressing objects: 100% (596/596), done.
remote: Total 875 (delta 279), reused 787 (delta 203), pack-reused 0
Receiving objects: 100% (875/875), 3.68 MiB | 912.00 KiB/s, done.
Resolving deltas: 100% (279/279), done.
</pre></figure>
<p>Let’s check that Maven and Java are correctly installed.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>java <span class="nt">-version</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
</pre></figure>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>mvn <span class="nt">-v</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: ...
Java version: 11.0.1, vendor: Oracle Corporation, runtime: ...
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
</pre></figure>
<p>The next step is to compile the project to produce the artifacts (i.e., binaries) that are required. To that end,
we use Apache Maven. Maven is an opiniated build tool:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Opinionated Software is a software product that believes a certain way of approaching a business process is inherently
better and provides software crafted around that approach.
</code></pre></div></div>
<p>Namely, following its opinion makes our life easier and requires less efforts. For more information and tutorials please refer to this <a href="https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">Maven Tutorial</a>. The output of the build process is a set of “JAR” files (i.e., JAVA library) that are stored in your local <code class="highlighter-rouge">~/.m2</code> repository for later use.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">cd </span>microservices/
<span class="nv">$ </span>mvn clean <span class="nb">install</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Parent Pom of the Pinfo Micro Services [pom]
[INFO] Counterparty Service [war]
[INFO] Instrument Service [war]
[INFO] Valuation Service [war]
[INFO] Regulatory Reporting Service [war]
[INFO] API Gateway Service [war]
[INFO]
[INFO] -------------------&lt; ch.unige:pinfo-micro-services &gt;--------------------
[INFO] Building Parent Pom of the Pinfo Micro Services 0.2.0-SNAPSHOT [1/6]
[INFO] --------------------------------[ pom ]---------------------------------
....
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Parent Pom of the Pinfo Micro Services 0.2.0-SNAPSHOT SUCCESS [ 3.216 s]
[INFO] Counterparty Service ............................... SUCCESS [ 42.866 s]
[INFO] Instrument Service ................................. SUCCESS [ 49.720 s]
[INFO] Valuation Service .................................. SUCCESS [ 32.623 s]
[INFO] Regulatory Reporting Service ....................... SUCCESS [ 23.048 s]
[INFO] API Gateway Service 0.2.0-SNAPSHOT ................. SUCCESS [ 22.796 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:55 min
[INFO] Finished at: 2019-02-20T18:09:09+01:00
[INFO] ------------------------------------------------------------------------
</pre></figure>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> Congratulations, you compiled the microservices. </div>
<p>At this point, you have manage to compile all of the Java code and you have created maven artifacts for each microservice (Java Archives a.k.a. JARs). However, as we continue, we will see in the next chapters that a micro-service architecture is much more than a bunch of micro-services. We will need a lot of additional 3rd party tools and services.
These additional services (e.g., logging, security) are usually provided as container images that runs on Docker.
To be able to run the microservices along side these “3rd” party tools, we need to package the microservice as Docker images.</p>
<p>Simply put, Docker provides lightweight virtualization. It has a smaller footprint compare to the usual Virtual Machine approaches (Virtual Box, VM Ware).
The main difference is that the OS system layer is not replicated in each container but rather shared.</p>
<p>Docker containers run Docker images that are merely lightweight Linux systems with additional softwares. For more about <a href="https://www.docker.com/">Docker</a>
Let’s first check whether Docker is properly installed.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker <span class="nt">-v</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
Docker version 18.09.2, build 6247962
</pre></figure>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker run hello-world</code></pre></figure>
<figure class="console-output"><pre class="console-output">
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
</pre></figure>
<p>Before we continue, let’s have a look at a docker survival kit:</p>
<ul>
<li><code class="highlighter-rouge">docker ps</code> displays all the running containers.</li>
<li><code class="highlighter-rouge">docker ps -a</code>displays all stopped container (not running but still using some resources).</li>
</ul>
<p>Based on that :</p>
<ul>
<li>we can kill all running containers by running <code class="highlighter-rouge">docker kill $(docker ps -q)</code></li>
<li>remove all stopped containers by running <code class="highlighter-rouge">docker rm $(docker ps -a -q)</code></li>
<li>finally <code class="highlighter-rouge">docker system prune</code> cleans up all dangling data.</li>
</ul>
<p>So the Docker daemon is up and running. Let’s create the Docker images for the microservices. This step will reuse the
JAR files created previously and package them along a Linux system so that every image can be run independently.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">mvn <span class="nb">install</span> <span class="nt">-Ppackage-docker-image</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Parent Pom of the Pinfo Micro Services 0.2.0-SNAPSHOT SUCCESS [ 6.114 s]
[INFO] Counterparty Service ............................... SUCCESS [ 59.134 s]
[INFO] Instrument Service ................................. SUCCESS [ 58.533 s]
[INFO] Valuation Service .................................. SUCCESS [ 42.806 s]
[INFO] Regulatory Reporting Service ....................... SUCCESS [ 33.979 s]
[INFO] API Gateway Service 0.2.0-SNAPSHOT ................. SUCCESS [ 14.134 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:35 min
[INFO] Finished at: 2019-02-20T18:58:34+01:00
[INFO] ------------------------------------------------------------------------
</pre></figure>
<p>All the Docker images for the microservices have been created. Let’s double check:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker image <span class="nb">ls</span> | <span class="nb">grep </span>unige</code></pre></figure>
<figure class="console-output"><pre class="console-output">
unige/regulatory-service latest 5859668ecfb1 12 seconds ago 778MB
unige/valuation-service latest 93516633b7b3 48 seconds ago 814MB
unige/instrument-service latest b1bded92050c About a minute ago 814MB
unige/counterparty-service latest 1789c8543673 2 minutes ago 780MB
unige/api-gateway latest b355613b0bbd 32 hours ago 371MB
</pre></figure>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> You now have Docker images for your microservices. At this point, we have Docker images for the microservices and for the api-gateway. </div>
<p>Let’s start a Docker container with the counterparty microservice and map the port <code class="highlighter-rouge">28080</code> of the container to the port <code class="highlighter-rouge">10080</code> of the host.
In principle, this will start a Linux OS and then start the microservice as the first process (PID 1). This container provides all the service, you would
expect from any Linux system such as network, security, and isolation.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span> docker run <span class="nt">--name</span> myCounterpartyService <span class="nt">-p</span> 10080:28080 unige/counterparty-service:latest</code></pre></figure>
<figure class="console-output"><pre class="console-output">
2019-02-26 22:28:06,527 INFO [org.jboss.as.server] (main) WFLYSRV0010: Deployed "counterparty-service-0.2.0-SNAPSHOT.war" (runtime-name : "counterparty-service-0.2.0-SNAPSHOT.war")
2019-02-26 22:28:06,569 INFO [org.wildfly.swarm] (main) THORN99999: Thorntail is Ready
</pre></figure>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> Open a browser and navigate to http://localhost:10080/counterparies It will display a long list of counterparties. </div>
<p>This demonstrates that a web services is listening on port <code class="highlighter-rouge">10080</code> of <code class="highlighter-rouge">localhost</code>. More specifically, we started a container with the image of the counterparty microservice. The port <code class="highlighter-rouge">28080</code> is mapped to port <code class="highlighter-rouge">10080</code> so that we can test it.
Furthermore, we named the container <code class="highlighter-rouge">myCounterpartyService</code>.</p>
<p>As it is a fully running Linux system, you can connect to the container to inspect it. In another console, we can run a <code class="highlighter-rouge">docker ps</code> command to list running containers.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">docker ps</code></pre></figure>
<figure class="console-output"><pre class="console-output">
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfb9acf07d79 unige/counterparty-service:latest "/bin/sh -c 'java -D…" 42 seconds ago Up 40 seconds 0.0.0.0:10080-&gt;8080/tcp myCounterpartyService
</pre></figure>
<p>As you can see, there is one running container name <code class="highlighter-rouge">myCounterpartyService</code> that listen on port <code class="highlighter-rouge">10080</code> of <code class="highlighter-rouge">localhost</code>.</p>
<p>Let’s test it by connecting to <code class="highlighter-rouge">http://localhost:10080/counterparties/724500J4K3Q60O9QLF45</code> either by using a browser or the <code class="highlighter-rouge">curl</code> command line. <code class="highlighter-rouge">counterparties</code> is the context name of the service and <code class="highlighter-rouge">724500J4K3Q60O9QLF45</code>is the id of one particular counterparty we want the details on.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">curl <span class="nt">-X</span> GET http://localhost:10080/counterparties/724500J4K3Q60O9QLF45</code></pre></figure>
<figure class="console-output"><pre class="console-output">
{"lei":"724500J4K3Q60O9QLF45","name":"Ton Smit Onroerend Goed B.V.","legalAddress":{"firstAddressLine":"Van Teylingenweg 126","city":"Kamerik","region":"","country":"NL","postalCode":"3471GG"},"registration":{"registrationAuthorityID":"RA000463","registrationAuthorityEntityID":"52431649","jurisdiction":"NL","legalFormCode":"54M6","category":"","registrationDate":1545264000000,"lastUpdated":1545264000000,"registrationStatus":"ISSUED","nextRenewalDate":1576800000000},"status":"ACTIVE"}
</pre></figure>
<p>We can stop the service as follow:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">docker stop myCounterpartyService</code></pre></figure>
<p>And check that nothing is running anymore:</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">docker ps</code></pre></figure>
<figure class="console-output"><pre class="console-output">
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
</pre></figure>
<p>So far we only ran one service, to run all the microservices (plus the message broker) we will compose the images by using <code class="highlighter-rouge">docker-compose</code>.
<code class="highlighter-rouge">docker-compose</code> is a way to script a series of complex Docker configuration to provide a coherent ecosystem.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">cd </span>docker-compose/
docker-compose <span class="nt">-f</span> docker-compose-microservices.yml up</code></pre></figure>
<figure class="console-output"><pre class="console-output">
instrument-service | 2019-02-28 07:55:54,602 INFO [org.apache.kafka.clients.consumer.internals.AbstractCoordinator] (EE-ManagedExecutorService-default-Thread-1) [Consumer clientId=consumer-1, groupId=pinfo-microservices] Successfully joined group with generation 14
instrument-service | 2019-02-28 07:55:54,606 INFO [org.apache.kafka.clients.consumer.internals.ConsumerCoordinator] (EE-ManagedExecutorService-default-Thread-1) [Consumer clientId=consumer-1, groupId=pinfo-microservices] Setting newly assigned partitions [instrumentsReq-0]
valuation-service | 2019-02-28 07:55:54,604 INFO [org.apache.kafka.clients.consumer.internals.AbstractCoordinator] (EE-ManagedExecutorService-default-Thread-1) [Consumer clientId=consumer-1, groupId=pinfo-microservices] Successfully joined group with generation 14
valuation-service | 2019-02-28 07:55:54,611 INFO [org.apache.kafka.clients.consumer.internals.ConsumerCoordinator] (EE-ManagedExecutorService-default-Thread-1) [Consumer clientId=consumer-1, groupId=pinfo-microservices] Setting newly assigned partitions [instruments-0]
</pre></figure>
<p>In another console, check the running containers</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">docker ps</code></pre></figure>
<figure class="console-output"><pre class="console-output">
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f7af748fe9ae unige/valuation-service:latest "/bin/sh -c 'java -D…" 3 minutes ago Up 3 minutes 0.0.0.0:12080-&gt;8080/tcp valuation-service
aea66ab35500 unige/instrument-service:latest "/bin/sh -c 'java -D…" 3 minutes ago Up 3 minutes 0.0.0.0:11080-&gt;8080/tcp instrument-service
2df3d6a8d6aa confluentinc/cp-kafka:5.1.0 "/etc/confluent/dock…" 33 hours ago Up 4 minutes 0.0.0.0:9092-&gt;9092/tcp kafka
f197de9c79fe zookeeper:3.4.9 "/docker-entrypoint.…" 33 hours ago Up 4 minutes 2888/tcp, 0.0.0.0:2181-&gt;2181/tcp, 3888/tcp zookeeper
</pre></figure>
<p>Now we are ready to test the microservices. Let’s check again that we can query counterparties.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">curl <span class="nt">-X</span> GET http://localhost:10080/counterparties/724500J4K3Q60O9QLF45</code></pre></figure>
<figure class="console-output"><pre class="console-output">
{"lei":"724500J4K3Q60O9QLF45","name":"Ton Smit Onroerend Goed B.V.","legalAddress":{"firstAddressLine":"Van Teylingenweg 126","city":"Kamerik","region":"","country":"NL","postalCode":"3471GG"},"registration":{"registrationAuthorityID":"RA000463","registrationAuthorityEntityID":"52431649","jurisdiction":"NL","legalFormCode":"54M6","category":"","registrationDate":1545264000000,"lastUpdated":1545264000000,"registrationStatus":"ISSUED","nextRenewalDate":1576800000000},"status":"ACTIVE"}
</pre></figure>
<p>Then let’s get a specific instrument</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">curl <span class="nt">-X</span> GET http://localhost:11080/instrument/1</code></pre></figure>
<figure class="console-output"><pre class="console-output">
{"id":1,"brokerLei":"254900LAW6SKNVPBBN21","counterpartyLei":"969500CHL179N00GX059","originalCurrency":"EUR","amountInOriginalCurrency":539926.20,"dealDate":-61630035780000,"valueDate":-61630035780000,"instrumentType":"B","isin":"BE7261065565","quantity":5445,"maturityDate":1577837340000}
</pre></figure>
<p>Next, we will propagate all the instruments to the message broker for the valuation service to read them and compute the actual valuation.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">curl <span class="nt">-X</span> POST http://localhost:11080/instrument/propagateAllInstruments</code></pre></figure>
<p>This is the actual result of the valuation of the portfolio.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">curl <span class="nt">-X</span> GET http://localhost:12080/valuation?currency<span class="o">=</span>USD</code></pre></figure>
<figure class="console-output"><pre class="console-output">
{"breakdownByInstrumentType":{"STOCK":376127254.270,"LOAN":317483580.00,"BOND":468433784.120,"DEPOSIT":71056222.00,"WARRANT":4847202.120},"breakdownByCurrency":{"CHF":70073308.00,"SGD":66540948.00,"EUR":913601713.74,"GBP":102726326.00,"USD":85005746.77},"reportingCurrency":"USD","currentValue":1237948042.510,"percentile95":0.0,"percentile99":0.0}
</pre></figure>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> Congrats, you just got all the microservies and the message broker running. </div>
<h1 id="bibliography">Bibliography</h1>
<ul>
<li>[1] N. Poulton, (2017) Docker Deep Dive</li>
<li>[2] Turnbull, J. (2014). The Docker Book: Containerization is the new virtualization.</li>
<li>[3] Mauro Vocale, Luigi Fugaro (2018). Hands-On Cloud-Native Microservices with Jakarta EE</li>
<li>[4] Raghuram Bharathan, (2015). Apache Maven Cookbook</li>
</ul></content><author><name></name></author><summary type="html">Introduction This series of blog posts aims at helping students at the University of Geneva to develop their first application following micro-service principles. Besides explaining the concepts and implementation details of micro-service architecture, we will as well discuss software development practices such as software factories and innovative deployment options such as containers and container composition. All samples and a complete working application can be found here on GitHub</summary></entry><entry><title type="html">Microservice Architecture - Part 2 (SSO, Logging, and all that)</title><link href="http://localhost:4000/2019/02/17/microservice-architecture-part-2.html" rel="alternate" type="text/html" title="Microservice Architecture - Part 2 (SSO, Logging, and all that)" /><published>2019-02-17T22:51:20+01:00</published><updated>2019-02-17T22:51:20+01:00</updated><id>http://localhost:4000/2019/02/17/microservice-architecture-part-2</id><content type="html" xml:base="http://localhost:4000/2019/02/17/microservice-architecture-part-2.html"><p>In <a href="https://www.hostettler.net/2019/02/17/microservice-architecture-part-1.html">part 1</a>, we discussed how to compile and deploy the microservices. Remember that the microservices themselves are only a part of the microservice architecture.
By its very nature, microservice architecture is distributed and that comes with a lot of benefits and some constraints.
One of these constraints is that all the non-functional features such as security, logging, testability have to take distribution into account.
Think of the microservice architecture as a city, where the microservice are people working in the city. In the city, you also need policemen, firefighters, teachers, healthcare providers to keep it up and running.
The higher the number of people working in the private sector (a.k.a., microservices), the higher the need for non-operational people (a.k.a., utilities).</p>
<h2 id="compiling-the-ui">Compiling the UI</h2>
<p>This sample microservice architecture does not focus much on the UI. It mainly serves the purpose of showing how to integrate
it with the rest of the architecture. We will not dive into details. Sufficient to say, that the example was built with <a href="https://angular.io/">Angular 7.0</a>
and the <a href="https://github.com/akveo/ngx-admin">ngx-admin dashboard</a>.
In development, the UI is compiled by <a href="https://www.npmjs.com/">npm</a> running on top of <a href="https://nodejs.org/en/">nodejs</a>.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">cd </span>web-ui
<span class="nv">$ </span>node <span class="nt">--version</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
10.15.0
</pre></figure>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>npm <span class="nt">--version</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
6.5.0
</pre></figure>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>npm <span class="nb">install</span></code></pre></figure>
<figure class="console-output"><pre class="console-output">
...
audited 31887 packages in 68.922s
</pre></figure>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>npm run-script build</code></pre></figure>
<figure class="console-output"><pre class="console-output">
69% building modules 1280/1296 modules 16 active ...components\footer\footer.component.scssDEPRECATION WARNING on line 1, column 8 of
Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.
Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.
Date: 2019-02-21T09:13:40.912Z
Hash: e3a111b6560428e93784
Time: 76066ms
chunk {app-pages-pages-module} app-pages-pages-module.js, app-pages-pages-module.js.map (app-pages-pages-module) 3.16 MB [rendered]
chunk {main} main.js, main.js.map (main) 1.92 MB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 492 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 8.84 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 1.32 MB [rendered]
chunk {styles} styles.js, styles.js.map (styles) 3.99 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 7.17 MB [initial] [rendered]
</pre></figure>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> You just compiled the UI based on Angular 7.0 </div>
<h2 id="composing-the-microservices">Composing the microservices</h2>
<p>At this point, we have all the necessary components. Let’s put everything together by starting the different Docker compositions. The order in which we start the compositions is
important as there are dependencies:</p>
<ul>
<li><code class="highlighter-rouge">docker-compose-microservices.yml</code> starts the <a href="https://kafka.apache.org/">Kafka</a> message broker and the microservices. We already tested this in <a href="https://www.hostettler.net/2019/02/17/microservice-architecture-part-1.html">part 1</a> to prove that all the microservices are available.</li>
<li><code class="highlighter-rouge">docker-compose-log.yml</code> starts an <a href="https://www.elastic.co/elk-stack">ElasticSearch, LogStash, and Kibana (ELK) suite</a> alongside a Logspout companion container to take care of logs. This aggregates <strong>ALL</strong> logs from all containers
and concentrate them into the ElasticSearch using Logstash. Kibana can then be used to analyze the logs and extract some intelligence, raise alerts and so on.</li>
<li><code class="highlighter-rouge">docker-compose-api-gw.yml</code> starts an api-gateway that routes the calls to the services and handle
security by delegating authentication to an identity manager called <a href="https://www.keycloak.org/">keyloak</a>. It also serves static content and as <a href="https://en.wikipedia.org/wiki/TLS_termination_proxy">TLS termination</a>.</li>
</ul>
<div class="alert alert-warning" role="alert"><i class="fa fa-warning"></i> <b>Important: </b> On Linux system you may get the following error message : max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]. If it is the case run the following command
in a console : sysctl -w vm.max_map_count=262144 </div>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">cd </span>docker-compose
<span class="nv">$ </span>docker-compose <span class="nt">-f</span> docker-compose-microservices.yml up &amp;
<span class="nv">$ </span>docker-compose <span class="nt">-f</span> docker-compose-log.yml up &amp;
<span class="nv">$ </span>docker-compose <span class="nt">-f</span> docker-compose-api-gw.yml up &amp;</code></pre></figure>
<figure class="console-output"><pre class="console-output">
counterparty-service | 2019-03-12 20:06:27,203 INFO [stdout] (default task-1) counterpar0_.registrationStatus as registr16_0_,
counterparty-service | 2019-03-12 20:06:27,203 INFO [stdout] (default task-1) counterpar0_.status as status17_0_
counterparty-service | 2019-03-12 20:06:27,203 INFO [stdout] (default task-1) from
counterparty-service | 2019-03-12 20:06:27,205 INFO [stdout] (default task-1) Counterparty counterpar0_
kafka | [2019-03-12 20:10:15,744] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
kafka | [2019-03-12 20:20:15,651] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
kafka | [2019-03-12 20:30:15,652] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
kafka | [2019-03-12 20:40:15,652] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
kafka | [2019-03-12 20:50:15,654] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
...
kibana | {"type":"response","@timestamp":"2019-03-12T20:53:56Z","tags":[],"pid":1,"method":"get","statusCode":302,"req":{"url":"/","method":"get","headers":{"user-agent":"curl/7.29.0","host":"localhost:5601","accept":"*/*"},"remoteAddress":"127.0.0.1","userAgent":"127.0.0.1"},"res":{"statusCode":302,"responseTime":3,"contentLength":9},"message":"GET / 302 3ms - 9.0B"}
kibana | {"type":"response","@timestamp":"2019-03-12T20:54:01Z","tags":[],"pid":1,"method":"get","statusCode":302,"req":{"url":"/","method":"get","headers":{"user-agent":"curl/7.29.0","host":"localhost:5601","accept":"*/*"},"remoteAddress":"127.0.0.1","userAgent":"127.0.0.1"},"res":{"statusCode":302,"responseTime":8,"contentLength":9},"message":"GET / 302 8ms - 9.0B"}
....
api-gateway | 192.168.128.15 - - [12/Mar/2019:20:02:36 +0000] "POST /plugins HTTP/1.1" 409 213 "-" "curl/7.29.0"
api-gateway | 2019/03/12 20:02:36 [notice] 41#0: *139 [lua] init.lua:393: insert(): ERROR: duplicate key value violates unique constraint "plugins_cache_key_key" "
api-gateway | Key (cache_key)=(plugins:oidc::::) already exists., client: 192.168.128.15, server: kong_admin, request: "POST /plugins HTTP/1.1", host: "api-gateway:8001"
</pre></figure>
<p>If everything went according to plan, you now have a working application ecosystem at <code class="highlighter-rouge">https://localhost</code>
Point your browser to <code class="highlighter-rouge">https://localhost</code> and you’ll get an nice UI.</p>
<figure class="image"><pre>
<img src="/figures/ui.png" alt="Angular 7.0 UI to the financial-app" />
<figcaption>Angular 7.0 UI to the financial-app</figcaption>
</pre>
</figure>
<p>By pointing it to the counterparty microservice at <code class="highlighter-rouge">https://localhost/api/v1/counterparty</code>, the API-gateway will detect that you are not authenticated and will redirect you
to the SSO platform to enter for credentials. Enter <code class="highlighter-rouge">user1/user1</code></p>
<figure class="image"><pre>
<img src="/figures/login.png" alt="Keycloack SSO login form" />
<figcaption>Keycloack SSO login form</figcaption>
</pre>
</figure>
<p>Once authenticated you get redirected to the orginal URL you requested (<code class="highlighter-rouge">https://localhost/api/v1/counterparty</code>)</p>
<figure class="image"><pre>
<img src="/figures/counterparty-service.png" alt="JSON result of the counterparty microservice that returns all counterparties." />
<figcaption>JSON result of the counterparty microservice that returns all counterparties.</figcaption>
</pre>
</figure>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> Kudos, you just completed the installation of a complete microservice ecosystem locally on your machine. </div>
<h2 id="dissecting-the-docker-composes">Dissecting the docker-composes</h2>
<p>As stated previously <code class="highlighter-rouge">docker-compose</code> composes several containers together to deliver a solution.
For instance, by starting the database first and then whatever service that requires a database.
Using <a href="https://docs.docker.com/compose/">docker-compose</a> you set the same parameters, environment variables,
volumes that you would when starting a container with the command line.</p>
<p>From a general point of view, a docker-compose yaml file defines a series of services (e.g., database, microservice, web server) and then a series of “shared” services such as volumes, networks and so on.</p>
<p>Let’s take the example of the <code class="highlighter-rouge">docker-compose-api-gw.yml</code> file.</p>
<ul>
<li>First <code class="highlighter-rouge">version "2.1"</code> defines the version of the syntax. Then <code class="highlighter-rouge">services</code> defines a section with a series of services.</li>
<li>In the below example, the first service is called <code class="highlighter-rouge">kong-database</code> and is based on a postgres database version 10 as stated by <code class="highlighter-rouge">image: postgres:10</code>. The name of the container (for instance what
will appear if you run <code class="highlighter-rouge">docker ps</code>) is <code class="highlighter-rouge">kong-database</code>. The hostname will also be called <code class="highlighter-rouge">kong-database</code>.</li>
<li>What follows, is a section that describes the networks the container is participating into. This is very useful to isolate the containers from one another from a network perspective.</li>
<li>The <code class="highlighter-rouge">environment</code> section defines environment variables (similar to <code class="highlighter-rouge">-e</code> in the command line).</li>
<li>The healthcheck section defines rules to state whether or not a container is ready for prime time
and heathly.</li>
<li>The <code class="highlighter-rouge">kong-database</code> example does not expose ports but it could do so by defining a <code class="highlighter-rouge">ports</code> section that list the mapping of the ports of the container to the port of the host system. <code class="highlighter-rouge">80:7070</code> means
the port <code class="highlighter-rouge">7070</code> of the container is mapped to the port <code class="highlighter-rouge">80</code> (http) of the host system.</li>
<li>Finally, the volumes section maps volumes from the host systems to the directory in the container. This is very useful to save the state of the container (e.g., database files)
or to put custom configurations in place.</li>
</ul>
<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="na">version</span><span class="pi">:</span> <span class="s2">"</span><span class="s">2.1"</span>
<span class="na">services</span><span class="pi">:</span>
<span class="na">kong-database</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">postgres:10</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">kong-database</span>
<span class="na">hostname</span><span class="pi">:</span> <span class="s">kong-database</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">backend-network</span>
<span class="na">environment</span><span class="pi">:</span>
<span class="na">POSTGRES_USER</span><span class="pi">:</span> <span class="s">kong</span>
<span class="na">POSTGRES_PASSWORD</span><span class="pi">:</span> <span class="s">kong</span>
<span class="na">POSTGRES_DB</span><span class="pi">:</span> <span class="s">kongdb</span>
<span class="na">healthcheck</span><span class="pi">:</span>
<span class="na">test</span><span class="pi">:</span> <span class="pi">[</span><span class="s2">"</span><span class="s">CMD"</span><span class="pi">,</span> <span class="s2">"</span><span class="s">pg_isready"</span><span class="pi">,</span> <span class="s2">"</span><span class="s">-U"</span><span class="pi">,</span> <span class="s2">"</span><span class="s">kong"</span><span class="pi">,</span> <span class="s2">"</span><span class="s">-d"</span><span class="pi">,</span> <span class="s2">"</span><span class="s">kongdb"</span><span class="pi">]</span>
<span class="na">interval</span><span class="pi">:</span> <span class="s">30s</span>
<span class="na">timeout</span><span class="pi">:</span> <span class="s">30s</span>
<span class="na">retries</span><span class="pi">:</span> <span class="m">3</span>
<span class="na">volumes</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">pgdata-kong:/var/lib/postgresql/data</span>
<span class="nn">...</span></code></pre></figure>
<p><br /></p>
<p>After that very quick introduction to <code class="highlighter-rouge">docker-compose</code> let’s have a look at the services delivered by the three <code class="highlighter-rouge">docker-compose</code> files of the demo:</p>
<h4 id="docker-compose-logyml-providing-a-logging-infrastructure"><code class="highlighter-rouge">docker-compose-log.yml</code>: Providing a logging infrastructure</h4>
<p>Microservice architecture are distributed by nature and therefore cross-cutting concerns such as logging must take that aspect into account and aggregate the logs of the different containers.
Without that it would be difficult to follow a user request that goes across many services to deliver the final value.</p>
<p>To implement it, we rely on the <a href="https://github.com/gliderlabs/logspout">logspout</a> log router. Logspout primarly captures all logs of all the running containers and route them to
a log concentrator. Logspout in itself does not do anything with the logs, it just routes them to something. In our case, that something is <a href="https://www.elastic.co/products/logstash">Logstash</a>.</p>
<p>Logstash is part of the ELK stack and is a pipeline that concentrates, aggregates, filters and stashes them in a database, usually <a href="https://www.elastic.co/products/elasticsearch">elasticsearch</a>.
Kibana depends on Elasticsearch and gets its configuration from a volumes shared from the host (<code class="highlighter-rouge">./elk-pipeline/</code>).
For more details about the Logstash configuration, please refer to <code class="highlighter-rouge">./elk-pipeline/logstash.conf</code>.</p>
<p><a href="https://www.elastic.co/products/elasticsearch">Elastic Search</a> stores, indexes and searches large amount of data. Like Logstash, it is distributed in nature.
Elasticsearch is starting first in <code class="highlighter-rouge">docker-compose-log.yml</code> because other services such as Logstash and Kibana depends on it.
Elasticsearch maps a host volume (<code class="highlighter-rouge">esdata1</code>) to its own data directory (<code class="highlighter-rouge">/usr/share/elasticsearch/data</code>). Thanks to that mapping, data are not lost when the container is stopped or if it crashes.</p>
<p>The final part of the puzzle is <a href="https://www.elastic.co/products/kibana">Kibana</a> which visualizes the data stored in Elasticsearch to do business intelligence on the logs. This is very
useful to get a clear and real time status of the solution. Kibana depends on Elasticsearch and exposes its interface to the port <code class="highlighter-rouge">5601</code> of the host.</p>
<p><br /></p>
<h4 id="docker-compose-api-gwyml--prodiving-api-gateway-services"><code class="highlighter-rouge">docker-compose-api-gw.yml</code> : Prodiving api-gateway services</h4>
<p>Microservice architecture are usually composed of a lot of services. Keeping track of these, providing and maintaining a clear API becomes very quickly challenging.
Besides, the granularity of microservices often call for a composition to deliver actual value add. Besides, different applications might have different needs. For instance, a mobile app might need a different API
than a web app.
Furthermore, we often want to secure some services. For instance, using <a href="https://oauth.net/2/">oauth2 protocol</a> connected to an identity provider to offer Single Sign On (SSO) on the services.</p>
<p>In our case, the API gateway is called <a href="https://konghq.com/solutions/gateway/">Kong</a> and it requires a database. The <code class="highlighter-rouge">docker-compose-api-gw.yml</code> describes the following services:</p>
<p><code class="highlighter-rouge">kong-database</code> which is a postgress database version 10 that holds the API gateway configuration</p>
<p>The api gateway itself <code class="highlighter-rouge">api-gateway</code> that is based on a docker image that we built previously <code class="highlighter-rouge">unige/api-gateway</code> when we ran <code class="highlighter-rouge">mvn clean install -Ppackage-docker-image</code> at the root of the project.
To get more details on how the image has been built, look at the <code class="highlighter-rouge">Dockerfile</code> in the <code class="highlighter-rouge">api-gateway/src/main/docker</code> directory. The image is based on <code class="highlighter-rouge">kong:1.1rc1-centos</code> but it is customized in several ways:</p>
<ul>
<li>There is an additional <a href="https://github.com/nokia/kong-oidc">plugin</a> to support openid</li>
<li>A customized <code class="highlighter-rouge">docker-entrypoint.sh</code> to start Kong as root so that we can attach it to ports <code class="highlighter-rouge">80</code> and <code class="highlighter-rouge">443</code> that are privileged.</li>
<li>A customer <code class="highlighter-rouge">nginx</code> template to enable serving static content (the UI).</li>
<li>A shell script called <code class="highlighter-rouge">config-kong.sh</code> that configures the API-gateway by defining the services and the routes to these services. By the way this file, is ran after the api-gateway is
started and labelled as healthy by the container called <code class="highlighter-rouge">api-gateway-init</code>.
The first line defines a service called <code class="highlighter-rouge">counterparty-service</code> that will route the request to the microservice <code class="highlighter-rouge">http://counterparty-service:8080/counterparties</code>. The servicer <code class="highlighter-rouge">counterparty-service</code> is the host name
given by the microservice configuration. The second line creates a route in the API-gateway to the previous service. In that case <code class="highlighter-rouge">/api/v1/counterparty</code>, please note that the api-gateway can
take care of versioning. Finally, the last line configures the OpenId plugin to provide authentication by telling the plugin to use the <code class="highlighter-rouge">api-gateway</code> client of the <code class="highlighter-rouge">apigw</code> realm of the keycloak.</li>
</ul>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c">#Creates the services.</span>
curl <span class="nt">-S</span> <span class="nt">-s</span> <span class="nt">-i</span> <span class="nt">-X</span> POST <span class="nt">--url</span> http://api-gateway:8001/services <span class="nt">--data</span> <span class="s2">"name=counterparty-service"</span> <span class="nt">--data</span> <span class="s2">"url=http://counterparty-service:8080/counterparties"</span>
...
<span class="c">#Creates the routes</span>
curl <span class="nt">-S</span> <span class="nt">-s</span> <span class="nt">-i</span> <span class="nt">-X</span> POST <span class="nt">--url</span> http://api-gateway:8001/services/counterparty-service/routes <span class="nt">--data</span> <span class="s2">"paths[]=/api/v1/counterparty"</span>
...
<span class="c">#Enable the Open ID Plugin</span>
curl <span class="nt">-S</span> <span class="nt">-s</span> <span class="nt">-i</span> <span class="nt">-X</span> POST <span class="nt">--url</span> http://api-gateway:8001/plugins <span class="nt">--data</span> <span class="s2">"name=oidc"</span> <span class="nt">--data</span> <span class="s2">"config.client_id=api-gateway"</span> <span class="nt">--data</span> <span class="s2">"config.client_secret=798751a9-d274-4335-abf6-80611cd19ba1"</span> <span class="nt">--data</span> <span class="s2">"config.discovery=https%3A%2F%2Flocalhost%2Fauth%2Frealms%2Fapigw%2F.well-known%2Fopenid-configuration"</span></code></pre></figure>
<p>A database for Keycloak the SSO software called <code class="highlighter-rouge">iam-db</code></p>
<p>The SSO service <code class="highlighter-rouge">iam</code> that is based on Keycloak v4.8.3. Please note that a complete configuration is loaded initially using <code class="highlighter-rouge">master.realm.json</code>. This configuration creates the required
realm, client and configuration to provide authentication to the api-gateway.</p>
<p><br /></p>
<h4 id="docker-compose-microservicesyml--micro-services-and-message-broker"><code class="highlighter-rouge">docker-compose-microservices.yml</code> : Micro-services and message broker</h4>
<p>Finally, the last of the composition are the microservices themselves. As you can see, most of the configuration is not required for the microservices themselves but for the infrastructure around it.
All the services belong to the <code class="highlighter-rouge">backend-network</code> nertwork.</p>
<p>First, it defines a <a href="https://zookeeper.apache.org/">ZooKeeper</a> that provides distributed configuration management, naming and group services. Zookeeper maintains its state in two shared volumes that are respectively mapped
to the <code class="highlighter-rouge">./target/zk-single-kafka-single/zoo1/data</code> and <code class="highlighter-rouge">./target/zk-single-kafka-single/zoo1/datalog</code> directories of the host. Zookeeper is a mandatory component for the message broker.</p>
<p>Second, it defines a Kafka container. <a href="https://kafka.apache.org/">Kafka</a> is a robust and fast message broker that excels at exchanging messages in a distributed way. It has a dependency to Zookeeper
and exposes its port <code class="highlighter-rouge">9092</code> to the same port on the host. It also saves its state on a mapped volume on the host.</p>
<p>Then, the counterparty service is a actual microservice (Finally !!!) that exposes its port <code class="highlighter-rouge">8080</code> to the port <code class="highlighter-rouge">10080</code> of the host. This microservice is based on <a href="https://thorntail.io/">Thorntail</a>.</p>
<p>The instrument service is special as it connects to the message broker (Kafka) to send messages that will be read later on by the valuation service.</p>
<p>The other microservices : valuation-service and regulatory-service are more of the same.</p>
<div class="alert alert-success" role="alert"><i class="fa fa-check-square"></i> <b>Tip: </b> Kudos, you completed the tour of the microservice sample. Next chapter dives into a bit of theory. </div></content><author><name></name></author><summary type="html">In part 1, we discussed how to compile and deploy the microservices. Remember that the microservices themselves are only a part of the microservice architecture. By its very nature, microservice architecture is distributed and that comes with a lot of benefits and some constraints. One of these constraints is that all the non-functional features such as security, logging, testability have to take distribution into account. Think of the microservice architecture as a city, where the microservice are people working in the city. In the city, you also need policemen, firefighters, teachers, healthcare providers to keep it up and running. The higher the number of people working in the private sector (a.k.a., microservices), the higher the need for non-operational people (a.k.a., utilities).</summary></entry><entry><title type="html">My two cents on SVN vs GIT</title><link href="http://localhost:4000/2016/02/27/my-two-cents-on-svn-vs-git.html" rel="alternate" type="text/html" title="My two cents on SVN vs GIT" /><published>2016-02-27T11:13:50+01:00</published><updated>2016-02-27T11:13:50+01:00</updated><id>http://localhost:4000/2016/02/27/my-two-cents-on-svn-vs-git</id><content type="html" xml:base="http://localhost:4000/2016/02/27/my-two-cents-on-svn-vs-git.html"><div class="alert alert-warning" role="alert"><i class="fa fa-warning"></i> <b>Important: </b> This post is 3 years old and a lot has changed in the mean time. I would now recommend to upgrade to Git.
Especially because the Cloud ecosystem is extremely dynamic. That being said, do it in a managed way starting by a low profile project. </div>
<hr />
<p><strong>Executive summary</strong> : Yes, Git is functionally richer and has several quality attributes that are really better than SVN but let’s face it : it comes with an extra layer of complexity. This complexity may (and did in several instances I am aware of) result in time to market issues, tensions during stressful phases, loss of commits, dreadful merges and major impacts on the release management process. Henceforth, the question is :</p>
<ul>
<li>Are the extra functionnalities worth the investment and the risks?</li>
</ul>
<p>In my opinion, Git is worth the investment if your devellopers are meant to work off site / off line.
If not (e.g., standard banking and financial industries) and it you already have an up and running SVN based software factory then do not bother
to migrate to Git for existing project. Try a proof of concept on a new <strong>low profile project</strong> and do not hesitate to invest in training <strong>and</strong> to re-engineer you existing release management processes. Once your teams have some experience with it, you can decide to migrate the existing codebase.
That’s beeing said, if you have no SCM then start with Git directly.</p>
<hr />
<h3 id="introduction">Introduction</h3>
<p>In many companies, SVN is still the SCM of choice (and yes some of them just finished up migrating from CVS). In the open-source world, the situation is very different. Indeed, Git is the de facto winner. As devellopers tend to stay up to date with the latest technologies, they want to migrate to the coolest new thing. I keep having discussions about GIT and whether or not a company or a department should migrate to it. In this blog post, I explain my position and argument on whether or not a company or department should move to Git.</p>
<h3 id="git-vs-svn">Git vs SVN</h3>
<p>There are plenty of very detailled comparison between Git and SVN out there. Among them let me cite the following articles [1] [2] [3].</p>
<p>Here a selection of the most important functionnal and non-functional Git features.</p>
<h4 id="dencentrilization">Dencentrilization</h4>
<p>Let me start with the obvious, Git is dencentrilized by design. This is great for highly collaborative and disseminated teams. Actually, this is most important feature. Basically, Git has been designed to answer that problematic.
This has also nice side effects :</p>
<ul>
<li>Working offline</li>
<li>Cloning a repository allows to quickly fork a project, make a couple of tests and submit a new version (by mean of pull requests) even if you do not have the commit rights.</li>
</ul>
<p>This is great but it is probably not the most useful features for teams working in closed business such as banking systems and other plateforms with very few mobility (for security reasons). Moreover, in these cases having conmit rights is definitely not an issue.</p>
<p><strong>Disseminated teams are a very compelling argument to migrate from SVN to Git. Of course, the contraposition is also true</strong></p>
<h4 id="branches">Branches</h4>
<p>Branches are feared in SVN and first class citizens in Git. This is definitly a game changer as it allows much better release management procedures.</p>
<h4 id="performances">Performances</h4>
<p>In both performance (chekout, checkin) and space GIT is the winner. For instance, using GIT the Mozillia projects gained a factor 30x is terms of space.</p>
<h4 id="useful-features">Useful features</h4>
<p>GIT comes with some nice tools that really improve the productivity of experienced developers. Here is a non-exhaustive list:</p>
<ul>
<li>
<p><code class="highlighter-rouge">git bisect</code> is great for investigating regressions and discover when that a given bug has been introduced.</p>
</li>
<li>
<p><code class="highlighter-rouge">git stash</code> takes all of the staged changes and stores them away somewhere. This is useful if you want to break apart a number of changes into several commits, or have changes that you don’t want to get rid of (i.e. “git reset”) but also don’t want to commit.
<code class="highlighter-rouge">git stash</code> puts staged changes onto the stash and <code class="highlighter-rouge">git stash pop</code> applies the changes to the current working copy.
It operates as a FILO stack (e.g. “First In, Last Out”) stack in the default operation.</p>
</li>
<li>
<p>Branches are lightweight and merging is easy, and I mean really easy. It’s distributed, basically every repository is a branch. It’s much easier to develop concurrently and collaboratively than with Subversion, in my opinion. It also makes offline development possible.</p>
</li>
</ul>
<h4 id="some-important-differences-to-know">Some important differences to know</h4>
<ul>
<li>
<p>SVN has predicticable and simple version numbers, Git relies on UUID.</p>
</li>
<li>
<p>GIT tracks contents rather than files</p>
</li>
</ul>
<h3 id="conclusion">Conclusion</h3>
<p>Yes, Git is functionally richer and has several quality attributes that are really better than SVN but let’s face it : it comes with an extra layer of complexity. This complexity may (and did in several instances I am aware of) result in time to market issues, tensions during stressful phases, loss of commits, dreadful merges and major impacts on the release management process.