SlideShare a Scribd company logo
Transactions: Case Study Svetlin Nakov National Academy for Software Development academy.devbg.org Transactions at the Supermarket’s Pay-Desk
Session and Transaction: Case Study We have a supermarket and we need to process orders An order is a set of order items (product, quantity) entered with a bar-code reader Processing a set of order items can take few minutes We should keep the transactions small to allow high concurrency What we can do?
Solution 1 Add Each Item in Separate Transaction
Case Study: Solution 1 Create an order in state  active=false , save it and commit the transaction Commit a transaction for each order item Persist orders items in the database in  active=false  state If save of order item fails, rollback the transaction and correct the invalid item Finally start an additional transaction, process the payment and commit it Change the order state to  active=true
Case Study: Solution 1 We have a series of small transactions Don’t keep long transactions in the DB Works well for Web applications How to deal with the following: Customer takes the last bottle of vodka but does not checkout Next customer comes and no vodka is available and goes off The first customer cancel his order We have 2 customers but have no sale
Solution 2 Keep Long Transaction Perform Critical Changes in the Last Moment
Case Study: Solution 2 Create an order and keep the transaction open during the processing of this order For each order item save it in the database and post the changes to DB If save fails  c orrect the invalid item and post it again (transaction is kept open) Finally process the payment (update product amounts and cash amounts) and commit the transaction If something fail, rollback the entire transaction
Case Study: Solution 2 We have only one transaction We kept it open for a long (few minutes) We add order items without changing the amount of ordered products Finally we change shared data (cash amount and product amounts) just before commit, when the customer pays The transaction is long but the time we keep locked records in small (few milliseconds)
Case Study: Solution 2 At the final stage some products can be unavailable We still use optimistic locking This gives good scalability Good for desktop applications only! When concurrent users are not too much Not applicable for Web scenario
Solution 3 Disconnected Model Keep All Changes in the Memory; Small Transaction Commits All of Them at Once
Case Study: Solution 3 Don't start any session and transaction Create an order in memory only (in transient objects) For each order item create it in memory only (in transient objects) Immediate data validation is not possible! Finally start session and transaction, save the order and order items , process the payment and commit the transaction If something fail, rollback the   transaction
Case Study: Solution 3 Classical “disconnected model” Efficient, optimistic locking Hard to implement If an order item fails to post in the DB, the entire order should be canceled No way to correct one item Good for mobile applications Avoid in Web and Desktop scenarios
Solution 4 Just Pessimistic Locking
Case Study: Solution 4 Start a transaction with serializable isolation level For each order item immediately post changes in the database Immediately correct the products availability and cash amount Finally commit the transaction Concurrent customers should wait each other No concurrent transactions
Transactions: Case Study Questions ?

More Related Content

PPT
Svetlin Nakov - Database Transactions
PPTX
Concurrency control
PPTX
Distributed datababase Transaction and concurrency control
PDF
Chapter 5 Database Transaction Management
DOC
Concurrency control
PPTX
Transaction and concurrency control
PPT
Concurrency (Distributed computing)
PPTX
Concurrency of Issues of Distributed Advance Transaction
Svetlin Nakov - Database Transactions
Concurrency control
Distributed datababase Transaction and concurrency control
Chapter 5 Database Transaction Management
Concurrency control
Transaction and concurrency control
Concurrency (Distributed computing)
Concurrency of Issues of Distributed Advance Transaction

What's hot (20)

PPT
Transactions (Distributed computing)
PPT
Databases: Concurrency Control
PPTX
Concurrency control
PPTX
Optimistic concurrency control in Distributed Systems
PPT
11. transaction sql
PPT
4. concurrency control
PPTX
protocols of concurrency control
PDF
Introduction to database-Transaction Concurrency and Recovery
PPT
Dbms sixth chapter_part-1_2011
PPTX
Transaction processing ppt
PPT
Transaction slide
PPT
Transaction management
PPT
Databases: Locking Methods
PPT
Lec08
PPT
Dbms ii mca-ch9-transaction-processing-2013
PPTX
Validation based protocol
PPTX
Concurrency control
PPTX
Transaction states PPT
PPT
Concurrency
PPT
15. Transactions in DBMS
Transactions (Distributed computing)
Databases: Concurrency Control
Concurrency control
Optimistic concurrency control in Distributed Systems
11. transaction sql
4. concurrency control
protocols of concurrency control
Introduction to database-Transaction Concurrency and Recovery
Dbms sixth chapter_part-1_2011
Transaction processing ppt
Transaction slide
Transaction management
Databases: Locking Methods
Lec08
Dbms ii mca-ch9-transaction-processing-2013
Validation based protocol
Concurrency control
Transaction states PPT
Concurrency
15. Transactions in DBMS
Ad

Similar to Svetlin Nakov - Transactions: Case Study (20)

PDF
Building Autonomous Services
PPTX
transactionprocessingppt-171212112608.pptx
PPTX
05 Identificación de Tareas y Contexto de Uso (UX)
DOCX
Synopsis of yashbazaar.com
 
PDF
Conceptual modeling of tasks models
PDF
Scaling a Core Banking Engine Using Apache Kafka | Peter Dudbridge, Thought M...
PDF
Being effective with legacy projects
PPTX
Unit iv -Transactions
PDF
Farming logs to save the weekend
PDF
Developer Day Tech Session at QuickBooks Connect Sydney 2017
PPTX
Super market billing system report in python
PPTX
The 8 hidden wastes
PPTX
Online shopping
PPT
Fault Handling in SOA Suite 11g
PDF
Online shopping project synopsis
PDF
DF2UFL 2012: Workflows: Making the MOST of Salesforce.com Native Functionality
PDF
Group - 9 Final Deliverable
PPT
Drupalcamp South Florida 2012 - Introduction to Drupal Commerce
DOCX
Super Mart Report.docx
PDF
Group Presentation on Bussiness Intelligence
Building Autonomous Services
transactionprocessingppt-171212112608.pptx
05 Identificación de Tareas y Contexto de Uso (UX)
Synopsis of yashbazaar.com
 
Conceptual modeling of tasks models
Scaling a Core Banking Engine Using Apache Kafka | Peter Dudbridge, Thought M...
Being effective with legacy projects
Unit iv -Transactions
Farming logs to save the weekend
Developer Day Tech Session at QuickBooks Connect Sydney 2017
Super market billing system report in python
The 8 hidden wastes
Online shopping
Fault Handling in SOA Suite 11g
Online shopping project synopsis
DF2UFL 2012: Workflows: Making the MOST of Salesforce.com Native Functionality
Group - 9 Final Deliverable
Drupalcamp South Florida 2012 - Introduction to Drupal Commerce
Super Mart Report.docx
Group Presentation on Bussiness Intelligence
Ad

More from Svetlin Nakov (20)

PPTX
AI and the Future of Devs: Nakov @ Techniverse (Nov 2024)
PPTX
AI за ежедневието - Наков @ Techniverse (Nov 2024)
PPTX
AI инструменти за бизнеса - Наков - Nov 2024
PPTX
AI Adoption in Business - Nakov at Forbes HR Forum - Sept 2024
PPTX
Software Engineers in the AI Era - Sept 2024
PPTX
Най-търсените направления в ИТ сферата за 2024
PPTX
BG-IT-Edu: отворено учебно съдържание за ИТ учители
PPTX
Programming World in 2024
PDF
AI Tools for Business and Startups
PPTX
AI Tools for Scientists - Nakov (Oct 2023)
PPTX
AI Tools for Entrepreneurs
PPTX
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
PPTX
AI Tools for Business and Personal Life
PDF
Дипломна работа: учебно съдържание по ООП - Светлин Наков
PPTX
Дипломна работа: учебно съдържание по ООП
PPTX
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
PPTX
AI and the Professions of the Future
PPTX
Programming Languages Trends for 2023
PPTX
IT Professions and How to Become a Developer
PPTX
GitHub Actions (Nakov at RuseConf, Sept 2022)
AI and the Future of Devs: Nakov @ Techniverse (Nov 2024)
AI за ежедневието - Наков @ Techniverse (Nov 2024)
AI инструменти за бизнеса - Наков - Nov 2024
AI Adoption in Business - Nakov at Forbes HR Forum - Sept 2024
Software Engineers in the AI Era - Sept 2024
Най-търсените направления в ИТ сферата за 2024
BG-IT-Edu: отворено учебно съдържание за ИТ учители
Programming World in 2024
AI Tools for Business and Startups
AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Entrepreneurs
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
AI Tools for Business and Personal Life
Дипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
AI and the Professions of the Future
Programming Languages Trends for 2023
IT Professions and How to Become a Developer
GitHub Actions (Nakov at RuseConf, Sept 2022)

Recently uploaded (20)

PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PDF
Roadmap Map-digital Banking feature MB,IB,AB
DOCX
Euro SEO Services 1st 3 General Updates.docx
DOCX
Business Management - unit 1 and 2
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PDF
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
DOC-20250806-WA0002._20250806_112011_0000.pdf
PDF
Business model innovation report 2022.pdf
PDF
Unit 1 Cost Accounting - Cost sheet
PPT
Data mining for business intelligence ch04 sharda
PPTX
Probability Distribution, binomial distribution, poisson distribution
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
PPTX
Amazon (Business Studies) management studies
PDF
Deliverable file - Regulatory guideline analysis.pdf
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
340036916-American-Literature-Literary-Period-Overview.ppt
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
unit 1 COST ACCOUNTING AND COST SHEET
Roadmap Map-digital Banking feature MB,IB,AB
Euro SEO Services 1st 3 General Updates.docx
Business Management - unit 1 and 2
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
New Microsoft PowerPoint Presentation - Copy.pptx
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
DOC-20250806-WA0002._20250806_112011_0000.pdf
Business model innovation report 2022.pdf
Unit 1 Cost Accounting - Cost sheet
Data mining for business intelligence ch04 sharda
Probability Distribution, binomial distribution, poisson distribution
COST SHEET- Tender and Quotation unit 2.pdf
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
Amazon (Business Studies) management studies
Deliverable file - Regulatory guideline analysis.pdf

Svetlin Nakov - Transactions: Case Study

  • 1. Transactions: Case Study Svetlin Nakov National Academy for Software Development academy.devbg.org Transactions at the Supermarket’s Pay-Desk
  • 2. Session and Transaction: Case Study We have a supermarket and we need to process orders An order is a set of order items (product, quantity) entered with a bar-code reader Processing a set of order items can take few minutes We should keep the transactions small to allow high concurrency What we can do?
  • 3. Solution 1 Add Each Item in Separate Transaction
  • 4. Case Study: Solution 1 Create an order in state active=false , save it and commit the transaction Commit a transaction for each order item Persist orders items in the database in active=false state If save of order item fails, rollback the transaction and correct the invalid item Finally start an additional transaction, process the payment and commit it Change the order state to active=true
  • 5. Case Study: Solution 1 We have a series of small transactions Don’t keep long transactions in the DB Works well for Web applications How to deal with the following: Customer takes the last bottle of vodka but does not checkout Next customer comes and no vodka is available and goes off The first customer cancel his order We have 2 customers but have no sale
  • 6. Solution 2 Keep Long Transaction Perform Critical Changes in the Last Moment
  • 7. Case Study: Solution 2 Create an order and keep the transaction open during the processing of this order For each order item save it in the database and post the changes to DB If save fails c orrect the invalid item and post it again (transaction is kept open) Finally process the payment (update product amounts and cash amounts) and commit the transaction If something fail, rollback the entire transaction
  • 8. Case Study: Solution 2 We have only one transaction We kept it open for a long (few minutes) We add order items without changing the amount of ordered products Finally we change shared data (cash amount and product amounts) just before commit, when the customer pays The transaction is long but the time we keep locked records in small (few milliseconds)
  • 9. Case Study: Solution 2 At the final stage some products can be unavailable We still use optimistic locking This gives good scalability Good for desktop applications only! When concurrent users are not too much Not applicable for Web scenario
  • 10. Solution 3 Disconnected Model Keep All Changes in the Memory; Small Transaction Commits All of Them at Once
  • 11. Case Study: Solution 3 Don't start any session and transaction Create an order in memory only (in transient objects) For each order item create it in memory only (in transient objects) Immediate data validation is not possible! Finally start session and transaction, save the order and order items , process the payment and commit the transaction If something fail, rollback the transaction
  • 12. Case Study: Solution 3 Classical “disconnected model” Efficient, optimistic locking Hard to implement If an order item fails to post in the DB, the entire order should be canceled No way to correct one item Good for mobile applications Avoid in Web and Desktop scenarios
  • 13. Solution 4 Just Pessimistic Locking
  • 14. Case Study: Solution 4 Start a transaction with serializable isolation level For each order item immediately post changes in the database Immediately correct the products availability and cash amount Finally commit the transaction Concurrent customers should wait each other No concurrent transactions