[go: up one dir, main page]

0% found this document useful (0 votes)
6 views1 page

Tech - Database

READ COMMITTED prevents dirty reads but allows data changes between queries, while REPEATABLE READ provides a consistent view of data throughout a transaction. Transaction propagation in Spring Boot determines how transactions behave across method calls, with types like REQUIRED and REQUIRES_NEW. Distributed transactions involve multiple operations across services, requiring solutions like Two-Phase Commit or compensating transactions to ensure consistency.

Uploaded by

leifjia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Tech - Database

READ COMMITTED prevents dirty reads but allows data changes between queries, while REPEATABLE READ provides a consistent view of data throughout a transaction. Transaction propagation in Spring Boot determines how transactions behave across method calls, with types like REQUIRED and REQUIRES_NEW. Distributed transactions involve multiple operations across services, requiring solutions like Two-Phase Commit or compensating transactions to ensure consistency.

Uploaded by

leifjia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Explain the difference between READ COMMITTED and REPEATABLE READ.

When would
you use each?
READ COMMITTED and REPEATABLE READ are two isolation levels I use often.
READ COMMITTED is the default in PostgreSQL. It prevents dirty reads (so you never see
uncommitted data), but between your queries, other transactions can change data you've already
read. This means if you check the same row twice, you might see different values.
REPEATABLE READ is MySQL's default and is more like taking a snapshot. Once your transaction
starts, all your queries see the same consistent data, even if other transactions make changes.
In real projects, because I usually use MySQL, the default REPEATABLE READ can handle most
scenarios, even money-related operations. With Spring Boot, I usually use @Transactional
annotation to configure isolation levels based on business case needs.
2. transaction propagation
Transaction propagation defines how transactions behave when methods call each other. In Spring
Boot, I use these common propagation types, for example, REQUIRED, it's a default mode in
spring, If a transaction exists, reuse it; otherwise, create a new one. REQUIRES_NEW , Always
create a new transaction, suspending the current one. it's very Useful for independent
operations(e.g., logging).

Describe distributed transactions. What are the common solutions to the


transaction consistency problem in distributed systems?
A distributed transaction involves multiple operations across different databases or services that need
to be treated as a single unit. That means either all operations succeed or all fail.
The causes of distributed transactions mainly come from the distributed nature of modern systems.
As services are split into microservices, a business operation may span multiple services and
databases. For example, in an e - commerce system, placing an order might involve updating the
inventory in one service and recording the order information in another.
Common solutions for transaction consistency include the Two - Phase Commit (2PC) protocol. It has
a coordinator to manage the commit process, but it has high latency and is not very fault - tolerant.
In distributed systems, we Ususally breaks a large transaction into a series of local transactions. If
one fails, compensating transactions are executed to reverse the effects of previous ones. For
example, in an e - commerce system, when a customer places an order, there are multiple steps like
reserving inventory, charging the customer, and shipping the product. Each step is a local
transaction. If the payment fails, we can have compensating transactions to release the inventory and
refund the customer.

You might also like