-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicroservicesDesignPatterns.txt
More file actions
607 lines (416 loc) · 18 KB
/
Copy pathMicroservicesDesignPatterns.txt
File metadata and controls
607 lines (416 loc) · 18 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
Microservices
...............................................................................................
Distributed Enterprise application:
The application developed, tested, deployed on server , distributed over network (internet)
Patterns(ways) for building Distributed Enterprise application:
Before 2010 -Monolithic Enterprise app
After 2010 - Microservices Enterprise app
Enterprise - domain - Banking
Banking:
Modules
1.Account Management - Service (mini application)
2.Customer Management
3.Loans Management
Microservice is way of building app testing, deploying, maintaining, independently.
Objective:
Automation. - Dev Ops and Cloud
CI AND CD
Deployment:
Moving app on to the data center.
Data center:
Servers + os(Linux)----> bare deployment...
VM -oracle vm
Lightweight vm - Containers - Docker
Cloud Computing:
Renting data centers
Application(software system) Development patterns:
.................................................
Network based Applications - Distributed Application
Application has layers:
1.User interface layer
2.Application biz layer
3.Data Layer /Repository layer
History of Architecture of Distributed Application
Distributed means, application is broken into multiple parts and each part put into multiple hosts/machines, connect those via network.
1.Mainframework based distributed
1.Application biz layer
2.Data Layer /Repository layer
Where as User interface layer is kept in dump terminals connected to mainfram.
Drawbacks:
1.Too costly
2.scalability is too difficult.
Advantage:
1.High security
2.Centeralized management.
2.Client Server Architecture
2.1.Main framework based client -server , where as mainframe acts as server and digital computers act as clients.
2.2.Digital computer based client - server Architecture
Servers and clients are digital computers
Based on this we can classify the applications layered /tiered concept
1.single tier/layer
client, server, database every is kept in one single machine...
2.two tier/layer
user interface is kept in client machine,
data logic and biz logic is kept in server machine
both machines are connected via networks
"This arch based on LAN /WAN"
3.three tier /layer
This arch based on "internet network" and web computing
client - client machine
server - biz logic is kept inside another machine
database - is kept inside another machine
Client is browser
Server BIZ logic is kept as "web Applications"
Database is accessed by "Server side technologies - J2EE,ASP/.net,PHP,....
4.N-tier / layer
Client is browser
Server BIZ logic is kept as "web Applications"
-Again spilt into multi layered
Database is accessed by "Server side technologies - J2EE,ASP/.net,PHP,....
In 2000 , J2EE introduced n-tier client server
browser -------web application(servlets/jsp)----EJB----Messaging/Databases(JMS/JDBC/Middlewares)
Spring based N-tier client server arch:
browser -------web application(spring mvc)---Spring services----Spring data----Messaging/Databases(JMS/JDBC/Middlewares)
.....................................................................................
How to build N-tier distributed Applications
.....................................................................................
Steps/Process:
1.Domain Modeling
Banking, Online Food Delivery App, Ecommerce Domain
2.Select technology
if your app is based on web and internet.
Steps:
1. Database - Oracle
2. MOM - RabbitMQ,IBM MQ,Microsoft MQ
3. Development Technology
Java/JEE - Why you go with specific implementation technologies?
.Net
Php
3.Development and release methodology
Waterfall - traditional dev , release
Any domain consist of various modules
-Accounts
-Loans
-Customers
-Card
etc.....
4.Testing
Once the development is over, the app is going to be under testing
5.Production
Once the app is tested fully, ready for production.
6.Maintance
Once the app in the production, it goes on maintaince...
if any app is built based on the above methodology, which is called as "Monolithic"
.....................................................................................
Challenges in the application development ,testing, release, Production ,maintaince
....................................................................................
1.Every thing has to go step by step - this increase cost , time waste, resource waste
Companies like Amazon, Netflix who wanted fast development,test,release,maintaince : Dynamic methodology to build applications - No downtime,
One module takes more time ,another module takes less time, because of one module , other module should not wait.
2.Technology bottleneck - Mono technology
The whole application is built using single technology - Java - vendor lock
The whole application targets single database - Oracle /Mysql/Microsoft SQL server..
3.Employing security layer is more complicated
4.Deployment / Production.
The dev and prod env is completely different
Bare deployment models
VM based deployment...
...................................................................................
New way of building apps
1.Automatation is key concept
from the Analysis ,dev ,test ,release, prod, maintaince
Agile :(Requirement Analysis)
Agile is an iterative approach to project management and software development that helps teams deliver value to their customers faster and with fewer headaches. Instead of betting everything on a "big bang" launch, an agile team delivers work in small, but consumable, increments
Breaks the application into smaller and smaller.
- fast delivery with quality on time.
Requirements are highly dynamic, cant be free zed, since it is dynamic start development ,test, release, deploy periodically.
We need automation, through which automatically only we can achieve fast delivery -
in order to automate, a new technology was created "Dev Ops" - Dev + Operations together.
Distributed source code repo - git
Pipe lines tools -
Jenkins -(Continuous Integration)
Requirement---> Dev---push the code to source code repo---|CI Tool---Compile--Build/pack--Testing-Deployment(CD)
Every thing is here Continuous happens
Continuous Req Analysis
Continuous Dev
Continuous release /build
Continuous test
Continuous release /build
Continuous deployment
Continuous tracing and monitoring
This process applied on every module in the applications
Order Management
Continuous Req Analysis,Dev,release,test,deployment,tracing,monitoring
CustomerManagement
Continuous Req Analysis,Dev,release,test,deployment,tracing,monitoring
if any app is built based on the above methodology, that application is called as "Microservice"
....................................................................................
What is Microservice?
Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of two or more services that are:
1.Independently deployable
2.Loosely coupled
Services are typically organized around business capabilities. Each service is often owned by a single, small team.
A Service is a "mini application" that implements narrowly focused functionality.
Such as orderManagement, customer Management, and so on....
....................................................................................
How to design and implement microservices
The microservices is all about practices followed, implemented, and tested in real time production grade applications in various companies like amazon,netflix,google,microsoft.
The many community people joined together who formed the pattern language in order to begin development of Microservices - Microservice pattern language, design patterns
if i want to build microservice based apps, how to begin , where to begin.
Microservices design patterns
.....................................................................................
....................................................................................
Microservice architecture pattern language
...................................................................................
The Microservice pattern language is a collection of patterns that help you architect an application using the microservice architectures.
Infrastructure Patterns:
Theses solves problems that are mostly infrastructure issues outside of development.
Application patterns:
These are for related to development
Application Infrastructure:
Application related infrastructures like containers
....................................................................................
Patterns for Decomposing an Application into services
1.Decompose by business capability
|
|
2.Decompose by subdomain
3.SelfContained Service
4.Service Per Team
.....................................................................................
Design patterns in Microservices
....................................................................................
Application Architecture Pattern
For building n-tier client server distributed application.
-Monolithic architecture
-Microservice architecture
Decomposition Pattern -Y scalling
1.Decompose by business capability
2.Decompose by subdomain
3.SelfContained Service
4.Service Per Team
MicroService Architecture Pattern------>Depcompostion Pattern
Decompose by business capability
If you are going to build online store.
Business capability:
Product Catalog Management
Inventory Management
Order Management
Delivery Management.
Alternate Pattern
Decompose by SubDomain:
Decompose the problem based on DDD principles.
....................................................................................
....................................................................................
Data Management
....................................................................................
Core Pattern:
1.Database Per Service Pattern
2.Shared Database
Note:
if you take any data related patterns, "Transactions" are very important.
1.Database Per Service Pattern leads/succeeds other patterns
Domain Event
Event Sourcing
Saga - Transaction
CQRS
API Composition
..................................................................................
Advance Data Management Pattern -Transactional Messaging Pattern
..................................................................................
1.Transactional outbox
2.Transactional log tailing
or
3.Polling publisher
2.1.Idemponent Consumer
.....................................................................................
.....................................................................................
Communication Style Patterns
...................................................................................
Service = Mini Application
MiniApplication = Collection of Programs
Collection of programs in Java = Collections of classes
Collections of classes = Collections Objects.
Object/Class = Collection of state and behaviour
State = data
Behaviour=methods
Object = methods
methods = API
API will DO three things
1.write - update,remove,insert
2.read
3.process
class OrderService {
@Autowrited
private OrderRepository orderRepo;
//API
public List<Order> findAll(){
orderRepo.findAll()
}
}
Types of API:
1.local api
api which are called with in same runtime by other apis
2.remote api
api which are called outside runtime via networks
How to build remote api?
Based on protocals
1.HTTP Protocal.
if you design your api based on HTTP protcal, those apis are called as "WebServices"
Web Service:
RESTFull WebServices,SOAP WebServices
REST API = Program
In java => classes
In Web Services classes are called "End Points"
In Micro services -Services can be represented as "WebServices"
Rest WebService------>http-----RestWebservice => HTTP based Microservice
Rest WebService------>http-----Graphql => HTTP based Microservice
Rest WebService------>http/2 over tcp------GRpc Service=> TCP based Microservice
Rest Web Service ---->TCP/MOM-------------->Messaging Service -Middlewares
Communication Sytle patterns:
1.RPI patterns
REST,gRPC,Apache Thrift - RPI implementations
2.Messaging
Any Messaging middlewares - RabbitMQ,IBM MQ,MicroSoft MQ - MQTT,AMQP
Streaming platforms - Apache Kafka,Confluent Kafka
2.1.Idemponent Consumer
3.Domain Specfic Protocal
SMTP - Mail Service
.....................................................................................
Deployment Patterns
.....................................................................................
Once the services(applications) are ready, we can move the application into production.
Production Related Patterns:
Deployment Environment/Plattforms
1.Bare Metal
Where as physical hardware, and operating system, Where we can provision our application.
If you deploy java application.
OS: Linux
JRE- 17
WebContainer -Tomcat
Databases -MySql
Streaming Platforms-Kafka
2.Virutal Machine
Oracle Virtual box
on VM , you can install os-linux
JRE- 17
WebContainer -Tomcat
Databases -MySql
Streaming Platforms-Kafka
3.Containerized Deployment
It is lightweight vm - Docker and Kubernets
JRE- 17
WebContainer -Tomcat
Databases -MySql
Streaming Platforms-Kafka
4.Cloud
->VM /container/bare
you can just deploy your app only,
cloud may give you all softwares for you...
"Cloud with containers are most preferable deployment for microservices"
Design patterns:
Bare Metal:
1.Multiple services instances per host
2.Service instance per host
VM
1.Service instance Per VM
Container
1.Service instance per Container
Cloud
1.server less deployment
2.Service deployment platform
3.container and cloud
if your app deployement is in container
or
in cloud
or
Container with cloud
or
in any Virtualized Env
if any micro service(application) is running in containerized env like kubernets(docker).
Challanges:
1.suppose the application is accessed by other application or external application
we need to communicate the application with help of "host:port".
if application is running Virtualized env, "host and port" is not static,it would be dynamic.
if it is dynamic then how other microservices, and external application, how they can communicate.
To solve the problem of identifying the services which are running in Virtualized env
Advanced Communication Patterns
(Service Registry and Discovery)
When we apply this pattern, services never communicate "directly", because they dont know each other due to "dynamic location",so they use broker to communicate, broker will have all service information-Service Registry
Service Registry Patterns:
1.Client side service Discovery
2.Server-side service Discovery
->Service Registry
->Self Registration
->ThridParty Registration
.....................................................................................
.....................................................................................
Services are running in Virtualized Env
Services are talking via Service Registry
What if i any service is down / Slow / Throwing Exception
Microservices provides a Design patterns to handle failures and slow calls
Service Reliablity Patterns
1.Timeout Pattern
2.Bulk Head Pattern
3.Retry Pattern
4.Circuit Breaker Patterns
.....................................................................................
.....................................................................................
Configuration Data and Its patterns
Every application which requires configuration data,the configuration data may be connection strings,api tokens,application settings etc...
In Java application, configuration data is kept inside properties or yml files...
What if in micro serivces, the configuration is need to be shared across the application?
We have design pattern to centeralize configuration data/information.
1.Microservice Chassis
2.Service Templates
3.Externalized COnfiguration
.....................................................................................
Micro services are ready in production
We have exposed our microservices via API Gateways
How to secure them?
Security Patterns
1.Access Tokens
-Authentecation
-Authrozation
-SSL
-Policies
.....................................................................................
Micro services are ready in production
Now we need to expose to
other Applications- User interface applications
Microservices provide you a design pattern, called
External API patterns:
1.API Gate ways
2.Back End for FrontEnd
.....................................................................................
.....................................................................................
....................................................................................
Now your Micro service is in Production
Next what should i do
Your App in Maintaince
Monitor Your apps......
Observablity Design patterns:
1.Log Management/Aggregation Pattern
2.Application Metrics Pattern
3.Audit Logging pattern
4.Distributed Tracing
5.Exception Tracker Pattern
6.Health Check API pattern
................................................................................
..............................................................................................
How to build Microservices?
There are plenty of Patterns available
How to implement these patterns and where to implement?
All programming languages support microservices via frameworks and libs
***********************************************************************************************************************************************************
Microservices implementation:
Java frameworks:
1.Spring boot with Spring cloud
2.Quarkus
3.Vertx
etc.....
JavaScript:
1.node.js with "Molculer.js"
2.node.js with "nest.js"
3.nodejs with "loopback.js"
etc.....