Concurrency phenomena are anomalies that every software developer should know. Learn about these in this excerpt from the book MariaDB for Developers.Concurrency phenomena are anomalies that every software developer should know. Learn about these in this excerpt from the book MariaDB for Developers.

Database Transactions: Everything That Can Go Wrong When Using Them

Note: This is an excerpt from an unedited version of my book MariaDB for Developers.


To this point, we have understood the concept of atomicity—either all operations succeed or none do. What can go wrong? It seems like we are covered. And we are. Until we introduce concurrency in our system. MariaDB is one of the most highly performant database systems and tries to parallelize processing to increase throughput.

\ Parallelizing means that MariaDB can execute transactions from different sessions at the same time by interleaving operations from different transactions instead of waiting for one to finish before starting the next. Each transaction has its own sequence of operations, but MariaDB executes them in overlapping order. Figure 8-2 shows two transactions (A and B) and multiple database operations interleaved through time.

Figure 8-2: Interleaving database operations for parallelism.

This interleaving allows MariaDB to use CPU and I/O resources more efficiently than without parallelism. This, however, opens the door to subtle problems when the parallel transactions read and write overlapping data. Let's study some of these problems known as concurrency phenomena.

Dirty Reads

Friday afternoon, and we've got a winner! Our to-do application—which by chapter 6 became more of a project management tool than a to-do app—is so central to the business that prizes are given to users who excelled at reporting bugs or helping its development. Our to-do application allows the HR team to grant prizes to users, and this use case involves reducing the quantity of the awarded prize in the prizes table.

\ Janet and Moe, both from HR, are using our to-do app at the same time. Janet is about to grant today's prize (named "Bagelers" in our database), while Moe is viewing a dashboard that shows an overview of the prize inventory. Jane selects the winner and the prize, and clicks on "Grant prize." Our to-do app starts a new transaction that decreases the quantity for Bagelers from 8 to 7.

\ At that moment, Moe refreshes the dashboard and sees that there are 7 Bagelers. However, the system crashes, and since the transaction was never committed, the new quantity is not written to disk. Jane gets an error, but Moe doesn't. To him, there are 7 Bagelers. He is seeing incorrect data. This is called a dirty read. Figure 8-3 shows an example of the sequence of operations that lead to a dirty read at time t3.

Figure 8-3: Example of dirty read phenomena.

Non-Repeatable Reads

A similar situation can occur when a transaction reads a value twice, but such value is modified between the reads by another transaction. In this case, the second read would obtain a different value. This phenomenon is called a non-repeatable read and can lead to incorrect results if the values are used for other calculations in the same transaction. Figure 8-4 shows a non-repeatable read at time t5.

Figure 8-4: Example of non-repeatable read phenomena.

Phantom Reads

If the write operation in the previous example implies inserting rows, we get what's called a phantom read phenomenon. Figure 8-5 shows a phantom read at time t5.

Figure 8-5: Example of phantom read phenomena.

Market Opportunity
Brainedge Logo
Brainedge Price(LEARN)
$0.00844
$0.00844$0.00844
-2.31%
USD
Brainedge (LEARN) Live Price Chart
Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact [email protected] for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.

You May Also Like

Gold Hits $3,700 as Sprott’s Wong Says Dollar’s Store-of-Value Crown May Slip

Gold Hits $3,700 as Sprott’s Wong Says Dollar’s Store-of-Value Crown May Slip

The post Gold Hits $3,700 as Sprott’s Wong Says Dollar’s Store-of-Value Crown May Slip appeared on BitcoinEthereumNews.com. Gold is strutting its way into record territory, smashing through $3,700 an ounce Wednesday morning, as Sprott Asset Management strategist Paul Wong says the yellow metal may finally snatch the dollar’s most coveted role: store of value. Wong Warns: Fiscal Dominance Puts U.S. Dollar on Notice, Gold on Top Gold prices eased slightly to $3,678.9 […] Source: https://news.bitcoin.com/gold-hits-3700-as-sprotts-wong-says-dollars-store-of-value-crown-may-slip/
Share
BitcoinEthereumNews2025/09/18 00:33
ZKP’s Proof Generation Edge: The $100M Privacy Layer DOGE and XRP Don’t Have

ZKP’s Proof Generation Edge: The $100M Privacy Layer DOGE and XRP Don’t Have

Dogecoin, XRP, and ZKP represent three very different bets for the next cycle,  and the market is already separating speculation from structure. The Dogecoin price
Share
Blockonomi2026/01/22 01:00
Why The Green Bay Packers Must Take The Cleveland Browns Seriously — As Hard As That Might Be

Why The Green Bay Packers Must Take The Cleveland Browns Seriously — As Hard As That Might Be

The post Why The Green Bay Packers Must Take The Cleveland Browns Seriously — As Hard As That Might Be appeared on BitcoinEthereumNews.com. Jordan Love and the Green Bay Packers are off to a 2-0 start. Getty Images The Green Bay Packers are, once again, one of the NFL’s better teams. The Cleveland Browns are, once again, one of the league’s doormats. It’s why unbeaten Green Bay (2-0) is a 8-point favorite at winless Cleveland (0-2) Sunday according to betmgm.com. The money line is also Green Bay -500. Most expect this to be a Packers’ rout, and it very well could be. But Green Bay knows taking anyone in this league for granted can prove costly. “I think if you look at their roster, the paper, who they have on that team, what they can do, they got a lot of talent and things can turn around quickly for them,” Packers safety Xavier McKinney said. “We just got to kind of keep that in mind and know we not just walking into something and they just going to lay down. That’s not what they going to do.” The Browns certainly haven’t laid down on defense. Far from. Cleveland is allowing an NFL-best 191.5 yards per game. The Browns gave up 141 yards to Cincinnati in Week 1, including just seven in the second half, but still lost, 17-16. Cleveland has given up an NFL-best 45.5 rushing yards per game and just 2.1 rushing yards per attempt. “The biggest thing is our defensive line is much, much improved over last year and I think we’ve got back to our personality,” defensive coordinator Jim Schwartz said recently. “When we play our best, our D-line leads us there as our engine.” The Browns rank third in the league in passing defense, allowing just 146.0 yards per game. Cleveland has also gone 30 straight games without allowing a 300-yard passer, the longest active streak in the NFL.…
Share
BitcoinEthereumNews2025/09/18 00:41