What is Decentralized Data - Software Architecture
What is Decentralized Data - Software Architecture
Benefits of microservices?
Scalability: Individual services can be scaled up or down
independently based on their specific needs, allowing the
application to handle varying loads efficiently. The benefit of
scalability
allows for the
number of
instances of
services to
differentiate between other services and a monolithic
application.
Fault Isolation: When a monolith instance goes down, all
services in that instance also go down. There is no isolation of
services when failures occur. But with microservices
architecture, if one service fails, it typically won't bring down
the entire application. Other services can continue to function,
minimizing downtime and impact on users.
Saga
A saga is a mechanism for managing potentially long-lived
transactions in a distributed system. Depends on the processing
needs of the transactions, there are 3 patterns:
o Routing Slip:
This pattern is useful for sequential operations that require
preconditions to be met.
This involves passing information from one microservice to another.
Each microservice acts based on the information provided in the
routing slip. If a microservice encounters an error, it updates the
routing slip based on its information and sends it to the previous
microservice.
o Choreography:
Microservices communicate using events. Operations send events
upon completion, which other microservices receive and act upon
based on their subscriptions. In case of failures, microservices may
need compensating transactions to revert changes. But not all
processes require compensating transactions or data restoration to a
previous state.
o Orchestration:
Microservices are contacted using commands directly from the
central process manager. If a step fails, compensating transactions
are initiated.
This pattern is crucial for managing complex business processes
where a central controller is responsible for coordinating multiple
microservices to achieve a common goal, while also handling errors
and exceptions effectively.
CQRS Pattern (Command Query Responsibility
Segregation)
CQRS is a good foundation for building decentralized systems. It is
a design pattern where the data models for writing (commands) and
reading (queries) are separated.
By splitting the microservice into two, each can be optimized for its
specific function, often using separate databases. The write database
is optimized for handling high volumes of incoming data, while the
read database is optimized with indexes for efficient data retrieval.
Event sourcing is great for processes handling financial transactions,
medical records, and even information for lawsuits. Also, it can
offset the role of the system.
Event Soucing Pattern
This pattern is also a good fit for decentralized systems due to its
inherent properties.
This is a design pattern where changes to the state of an application
are stored as a sequence of events. Instead of only storing the
current state of data, it retains a history of all changes made to the
data. When an update occurs, the new value doesn’t overwrite the
previous one. Instead, an event representing this change is stored.
Eventual Consistency
Eventual consistency is a common concept used in managing data
across microservices, which are essentially decentralized in nature.
This is a technique to ensure data eventually reaches a consistent
state across these decentralized stores.
Because microservices are independent applications communicates
using network, delays are expected. Therefore, designing
microservices with strong consistency can cause latency.
On the other hand, eventual consistency allows temporary
inconsistency after updates, but offers higher availability and
scalability. For most applications, eventual consistency's benefits
outweigh the drawbacks, especially for large-scale systems.
Data Warehouse
A data warehouse is a large storage for various types of data from
multiple sources. This data is historical and can be used for
reporting and analysis. Data warehouses are different from OLTP
databases, which are used for transactions. Data warehouses use
OLAP databases, which are good for analytics. Data from OLTP
databases can be loaded into OLAP databases using ETL tools.
Microservices can also send data to data warehouses. Data
warehouses can be used to combine data from multiple sources into
a meterialized view that allow applications to retrieve predefined
views of data.
Transitioning from a monolithic system to
microservices architecture?
Incremental Migration: This involves starting small by
identifying and extracting specific functionalities from the
monolith into independent microservices.
Infrastructure Setup: Before diving into microservice
development, it's crucial to establish essential infrastructure
like CI/CD pipelines and a dedicated team to handle
development and management tasks.
Code Separation and Refactoring: Analyze the monolith to
pinpoint functionalities suitable for microservices. Then,
refactor dependent code within the monolith to interact with
the new microservice through APIs.
Database Management: Gradually migrate microservices to
their own independent databases to ensure data ownership and
integrity. Strategies like the Strangler Pattern and feature
flags can be used to manage this transition smoothly.
Loose Coupling: Continuously strive to loosen dependencies
between the microservices and the monolith, aiming for
eventual microservice independence. This might involve
further splitting functionalities within the monolith if
necessary.
Conclusion
Decentralizing data is a critical aspect of microservices
architecture, enabling services to operate independently,
scale effectively, and maintain high availability and fault
tolerance. By adopting strategies like independent data
stores, service discovery, and eventual consistency,
organizations can overcome the limitations of monolithic
architectures and leverage the full potential of
microservices. As microservices continue to evolve,
emerging technologies and practices will further enhance
the capabilities and efficiency of decentralized data
management, paving the way for more resilient and
scalable systems.