LECTURE 1: MICROSERVICESARCHITECTURE
1.1 Introduction to Monolithic & Microservices Architecture
1.2 Characteristics and Benefits of Microservices
1.3 Challenges of Microservices
1.4 Design Principles: Single Responsibility, Decentralized Data
Management
1.5 Use Cases and Industries Adopting Microservices
MONOLITHIC ARCHITECTURE:
Definition: Ina monolithic architecture, an
application is built as a single, tightly integrated unit
where all components are interconnected and run
together as a single codebase.
5.
MICROSERVICES ARCHITECTURE
Definition:
Microservices architectureis an approach to software
design and development where a complex
application is decomposed into a set of small, loosely
coupled services that can be developed, deployed,
and scaled independently.
SIMPLICITY OF DEVELOPMENT:
•Monolithic (Pros): Developing and maintaining a single
codebase is simpler and requires less overhead in terms of
managing multiple services and communication between
them.
• Microservices (Cons): Microservices involve the complexity of
distributed systems, which can make development and
debugging more challenging.
11.
EASE OF LOCALTESTING
• Monolithic (Pros): Testing a monolithic application is
often easier since all components run within the same
process, simplifying debugging and local testing.
• Microservices (Cons): In microservices, testing often
requires more complex setups due to the distributed
nature of the architecture.
12.
LOWER LATENCY:
• Monolithic(Pros): Communication within a monolithic
application typically involves lower latency compared
to network communication between microservices.
• Microservices (Cons): Inter-service communication in
microservices can introduce additional latency,
especially in scenarios with high request volume.
13.
SYNCHRONIZATION AND TRANSACTIONS:
•Monolithic (Pros): Maintaining data consistency and enforcing
transactions across the entire application is more
straightforward in monolithic databases.
• Microservices (Cons): Implementing distributed transactions
and ensuring data consistency can be complex in a
microservices architecture.
14.
DEPLOYMENT SIMPLICITY
• Monolithic(Pros): Deploying a single application is generally
less complex than coordinating the deployment of multiple
microservices.
• Microservices (Cons): Deploying microservices may require
additional tooling and processes for orchestration and version
management.
15.
SINGLE CODEBASE:
• Monolithic(Pros): Working with a single
codebase can simplify version control and
codebase management.
• Microservices (Cons): In microservices,
multiple codebases need to be maintained,
which can be more challenging to manage.
SCALABILITY
• Microservices (Pros):You can independently scale
individual microservices to handle increased loads,
optimizing resource usage.
• Monolithic (Cons): Scaling in a monolithic architecture
often requires scaling the entire application, which can be
inefficient and costly.
18.
FLEXIBILITY IN TECHNOLOGYSTACK:
• Microservices (Pros): Each microservice can use the most
suitable technology stack for its specific task, allowing for
innovation and flexibility.
• Monolithic (Cons): In a monolithic application, you're typically
locked into a single technology stack for the entire system,
limiting your choices.
19.
EASE OF MAINTENANCE:
•Microservices (Pros): Updates and maintenance
can be performed on individual microservices
without affecting the entire system.
• Monolithic (Cons): Making changes in a monolithic
codebase can be risky, as a small error can impact
the entire application.
20.
FASTER DEVELOPMENT:
• Microservices(Pros): Different teams can work
concurrently on separate microservices, speeding up
development.
• Monolithic (Cons): In a monolithic system,
coordination among developers working on different
features can be challenging and time-consuming.
21.
ISOLATION OF FAILURES:
•Microservices (Pros): Failures in one microservice are
less likely to impact the entire application because of
their isolation.
• Monolithic (Cons): A bug or failure in one part of a
monolithic application can potentially bring down the
entire system.
22.
CONTINUOUS DEPLOYMENT:
• Microservices(Pros): Microservices can be
independently deployed, enabling continuous
delivery and faster release cycles.
• Monolithic (Cons): In monolithic systems, deploying
updates can be a complex process, often requiring
downtime.
23.
EASIER TESTING:
• Microservices(Pros): Testing individual
microservices is more straightforward and can be
automated effectively.
• Monolithic (Cons): Comprehensive testing in
monolithic applications can be time-consuming
and complex.
USE MONOLITHIC WHEN:
•Building a new app (faster to get started)
• Small team (less coordination overhead)
• Simple application with few features
• Learning software development
Example: A startup's first product, a class project, a simple
internal tool
26.
USE MICROSERVICES WHEN:
•Large, complex application with many features
• Millions of users
• Multiple teams working independently
• Different parts need different scaling
• High reliability required (can't afford downtime)
• Application is mature and stable
Example: Netflix, Uber, Amazon, Spotify, Facebook
27.
CONCLUSION:
The choice betweenmonolithic and microservices architectures
depends on factors such as the application's complexity,
scalability requirements, development team structure, and
deployment needs. While monolithic architectures can simplify
certain aspects of development, microservices architectures
offer greater flexibility, scalability, and maintenance advantages,
particularly in complex and rapidly evolving systems.
1. SYSTEM UNDERSTANDING
Questions:
•What is the purpose of the
system?
• What problems should it
solve?
• Who will use the system?
• What are the main business
needs?
Output:
✓Business
requirements
✓ System goals
30.
EXAMPLE: FACEBOOK
Questions
• Whatis the purpose of Facebook?
• Who uses Facebook?
• What problems does Facebook solve?
• What features do users need?
31.
GATHER FUNCTIONAL ANDNON-FUNCTIONAL
REQUIREMENTS
Functional Requirements:
• Users can create an account.
• Users can post photos and
videos.
• Users can like and comment
on posts.
• Users can send messages.
Non-Functional
Requirements:
• Fast loading of posts.
• Secure user accounts.
• Available 24/7 worldwide.
32.
2. BUSINESS DOMAINANALYSIS
Goal: Identify the main business functions.
Example:
Questions:
✓What business capabilities exist?
✓What are the major workflows?
✓Who are the stakeholders?
✓How does the business operate?
Output: Business Capabilities
Business Processes
33.
EXAMPLE: FACEBOOK
Questions:
• Whatfeatures does
Facebook provide?
• What activities do users
perform?
•User Registration
•Posting Content
•Messaging
•Notifications
•Reactions (Likes)
4. DEFINE SERVICERESPONSIBILITIES
Goal:
Decide what each service can do.
Output:
Service Boundaries
37.
EXAMPLE: FACEBOOK
User Service→ Manages user accounts
Post Service → Creates and stores posts
Message Service → Handles chat messages
Notification Service → Sends alerts
EXAMPLE: FACEBOOK
When auser likes a post:
User
↓
Like Service
↓
Notification Service6
↓
Post Owner Receives Notification
40.
6. DESIGN DATAFLOW
Goal:
• Understand how data moves between services.
Output:
Data Flow Diagram (DFD)
Data Movement Description
Service Interaction Flow
41.
WHAT IS DATAFLOW?
Data Flow shows how information moves
from one user, service, or database to
another.
In microservices, data does not stay in one
place. It travels between services.
42.
FACEBOOK EXAMPLE: CREATINGA POST
Step 1: User Creates a Post
Anna uploads a photo and writes: "Enjoying my
vacation!“
Data Generated:
• User ID
• Photo
• Caption
• Date and Time
43.
FACEBOOK EXAMPLE: CREATINGA POST
Step 2: Post Service
Receives the Data
• Post Service
Responsibilities
• Validate the post
• Check whether Anna is
logged in
• Process the uploaded
photo
User
↓
Post Service
FACEBOOK EXAMPLE: CREATINGA POST
Step 4: Notification
Service is Triggered
Message sent:
User 1001 created
a new post.
Post Service
↓
Notification
Service
46.
FACEBOOK EXAMPLE: CREATINGA POST
Step 5:
Notification Service
Alerts Friends
Notification Service
↓
User's Friends
EXAMPLE: FACEBOOK
4. LikeDatabase:
Stores likes on posts..
Like Table
• LikeID(PK)
• PostID
• UserID
• DateLiked
54.
EXAMPLE: FACEBOOK
5. NotificationDatabase:
Stores notifications sent to
users.
Notification Table
• NotificationID(PK)
• UserID
• Message
• DateCreated
• Status
55.
8. DEPLOYMENT &TESTING
Purpose:
Build the system, deploy them, and make
sure they work correctly.
56.
9. MONITORING &MAINTENANCE
Purpose
Keep the system healthy after deployment.
Activities
• Monitor system performance
• Check for errors.
• Fix bugs.
• Add new features.
APPLICATION PROGRAMMING INTERFACE(API)
• API (Application Programming Interface) is a set of
rules, protocols, and tools that allows different
software systems to communicate and interact with
each other. It defines how requests and data should be
exchanged between systems, enabling them to work
together seamlessly without needing to know the
internal details of each system.
59.
WHY ARE API’SIMPORTANT IN MODERN
SOFTWARE?
• Flexibility: Developers can build different parts
independently.
• Modularity: Software is broken into pieces that can work
together.
• Scalability: Systems can grow by adding or updating parts
without rewriting everything.
60.
COMMON API CALLTYPES:
• GET: Gets or fetches information from a service.
• POST: Sends new information to create something in
the service.
• PUT/PATCH: Changes or updates information that’s
already there.
• DELETE: Removes or deletes information from the
service.
61.
How the APIworks step-by-step in this social media app example:
• GET: When you open the app to see your news feed or profile, the app
sends a GET request to the server asking, “Please send me the latest posts
or my profile details.” The server then responds by sending back that
information, which the app displays for you.
• POST: When you write a new post or upload a photo, the app sends a POST
request to the server with the new content. This tells the server, “Here is
new data to add,” so the server saves your post or photo and makes it
visible to others.
• PUT/PATCH: If you update your profile info or edit a post, the app sends a
PUT or PATCH request with the updated details. This tells the server, “Please
change the existing information to this new version,” so the server updates
the data accordingly.
• DELETE: When you delete a post or comment, the app sends a DELETE
request to the server saying, “Please remove this item.” The server then
deletes it from the database so it no longer appears in your feed.
SERVICE COORDINATION:
As thenumber of services increases, managing inter-
service communication and coordination becomes more
complex. Service interactions, such as synchronous and
asynchronous communication, event-driven
architectures, and data consistency across services, need
to be carefully designed and implemented.
64.
DATA MANAGEMENT:
Data managementbecomes more challenging in a
microservices architecture. Each service may have its own
database, leading to data duplication and potential data
consistency issues. Implementing strategies for data
synchronization, eventual consistency, and maintaining
data integrity across services is crucial.
65.
DISTRIBUTED SYSTEM COMPLEXITY:
Microservicesarchitecture introduces the
complexity of managing a distributed system.
Issues such as network latency, partial failures,
message delivery guarantees, and distributed
transactions need to be carefully addressed to
ensure the overall system's reliability and stability.
66.
OPERATIONAL OVERHEAD:
With multipleservices running independently,
operational tasks such as monitoring, logging,
deployment, and scaling become more
complex.
67.
SERVICE DISCOVERY ANDORCHESTRATION:
As the number of services grows, service discovery and
orchestration become crucial. Tools and mechanisms for
service registration, discovery, load balancing, and
routing need to be implemented to ensure seamless
communication and scalability.
68.
TESTING COMPLEXITY:
Testing amicroservices architecture requires more
comprehensive and sophisticated testing strategies.
Apart from unit testing individual services, integration
testing, end-to-end testing, and testing service
interactions become important. Setting up test
environments and data management for testing can be
challenging.
69.
ORGANIZATIONAL AND TEAMALIGNMENT:
Microservices architecture requires teams to be
organized around specific services or functional areas.
Coordinating and aligning the efforts of multiple teams,
managing inter-team dependencies, and maintaining
consistent development practices across teams can be
challenging.
70.
OPERATIONAL MONITORING AND
OBSERVABILITY:
Monitoringand gaining visibility into a distributed system
can be more complex in a microservices architecture.
Capturing and analyzing logs, metrics, and traces across
multiple services becomes crucial for troubleshooting,
performance optimization, and ensuring system health.
71.
DEPLOYMENT COMPLEXITY:
Deploying andmanaging multiple services,
potentially using different technologies and versions,
can be complex. Adopting containerization and
orchestration tools like Docker and Kubernetes can
help streamline the deployment process, but they
also introduce their own learning curve and
operational challenges.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
E-commerce Platforms:
Online retailers use microservices to manage
product catalogs, payments, recommendations,
and customer accounts independently,
facilitating rapid changes and updates.
74.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Finance and Banking:
Microservices enable financial institutions
to build agile systems for account
management, payment processing, risk
assessment, and fraud detection.
75.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Travel and Hospitality:
Booking systems, reservations, loyalty programs,
and customer reviews can be efficiently managed
through microservices, offering better user
experiences.
76.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Healthcare:
Healthcare providers utilize microservices to
develop interoperable systems for electronic
health records (EHR), patient management,
appointment scheduling, and telemedicine.
77.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Entertainment and Media:
Streaming platforms, content delivery, user
profiles, and recommendation engines
benefit from microservices' ability to
handle high volumes of data and user
interactions
78.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Gaming:
Online gaming companies use microservices
for game logic, matchmaking, player profiles,
leaderboards, and real-time updates.
79.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Logistics and Transportation:
Microservices assist in building scalable systems
for route optimization, tracking, inventory
management, and supply chain visibility.
80.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Manufacturing:
Manufacturing industries adopt microservices
for production line control, quality assurance,
inventory management, and predictive
maintenance.
81.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Telecommunications:
Telecom companies utilize microservices to
develop services like billing, customer
support, network management, and
provisioning.
82.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Energy and Utilities:
Microservices help in monitoring and
controlling infrastructure, managing
energy distribution, and optimizing
resource usage
83.
USE CASES ANDINDUSTRIES ADOPTING
MICROSERVICES
Government and Public Services:
Government agencies use microservices to
modernize citizen services, such as tax filing, permit
applications, and information dissemination.
Stay curious, remaindiligent, and
approach each new chapter with
enthusiasm.
Remember that the journey of learning
is a continuous one, and your
commitment to it will undoubtedly
lead you to remarkable
accomplishments.