SlideShare a Scribd company logo
1 of 7
Native DB transactions
In Sails.js
Sails.js
● MVC web application framework inspired by Ruby on Rails
● Built on Node.js and Express.js
● Delivered with Waterline ORM containing a set of adapters to various
databases
The problem
Request context
There is no ability to get
the current request/
user/session in any
application place.
Because of async nature
of the JS they should be
passed as function
arguments.
Random DB connection
DB adapter uses only
one connection for each
request or random from
pool (if pool mode is on).
Error handling
In case of uncatched
exception there is no
chance to figure to
whom the response
should be sent to.
Domain API
var domain = require('domain');
domain = domain.create();
const net = require('net');
net.createServer((req, res) => {
domain.run(() => {
setImmediate(() => {
let active = require('domain').active;
res.write('bye');
res.end();
});
});
}).listen(8000);
The solution
Request identification
Generate and assign
uuid for each incoming
request. Store request
with its id to domain in
the middleware.
DB adapter
Take request from the
domain context and use
dedicated DB connection
for each request.
Finalize request
Commit or rollback
transaction and return
connection to the pool.
Express
middleware
Create domain, set
request to the domain,
start the transaction
Custom DB
adapter
Checks current domain and
uses dedicated connection.
Single transaction for the
whole request lifecycle
Business
logic
Has access and can
store data to its own
request context
Single
response point
Finish transaction and
release connection
Thank you
Q/A

More Related Content

Similar to Native DB transactions

Node.js and Cassandra
Node.js and CassandraNode.js and Cassandra
Node.js and CassandraStratio
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...Juarez Junior
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
ASP.NET MVC Performance
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performancerudib
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js PlatformNaresh Chintalcheru
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBRob Tweed
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Ayes Chinmay
 
SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8Ben Abdallah Helmi
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.jsFDConf
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure OverviewEric Nelson
 

Similar to Native DB transactions (20)

Node.js and Cassandra
Node.js and CassandraNode.js and Cassandra
Node.js and Cassandra
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
11. jdbc
11. jdbc11. jdbc
11. jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
ASP.NET MVC Performance
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performance
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDBDeveloping node-mdb: a Node.js - based clone of SimpleDB
Developing node-mdb: a Node.js - based clone of SimpleDB
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
 
SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8
 
Express js
Express jsExpress js
Express js
 
Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.js
 
Lecture17
Lecture17Lecture17
Lecture17
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure Overview
 

More from UP2IT

Microservices. Mastering Chaos
Microservices. Mastering ChaosMicroservices. Mastering Chaos
Microservices. Mastering ChaosUP2IT
 
Сочетание классической и гибкой методологий управления проектами
Сочетание классической и гибкой методологий управления проектамиСочетание классической и гибкой методологий управления проектами
Сочетание классической и гибкой методологий управления проектамиUP2IT
 
Go для веба глазами PHP-разработчика
Go для веба глазами PHP-разработчикаGo для веба глазами PHP-разработчика
Go для веба глазами PHP-разработчикаUP2IT
 
Дизайнер в эпоху цифровых перемен
Дизайнер в эпоху цифровых переменДизайнер в эпоху цифровых перемен
Дизайнер в эпоху цифровых переменUP2IT
 
Продуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктів
Продуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктівПродуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктів
Продуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктівUP2IT
 
Модели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITION
Модели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITIONМодели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITION
Модели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITIONUP2IT
 
VR/AR в бизнесе
VR/AR в бизнесеVR/AR в бизнесе
VR/AR в бизнесеUP2IT
 
Hell 2 Heaven or Choosing Cloud Provider
Hell 2 Heaven or Choosing Cloud ProviderHell 2 Heaven or Choosing Cloud Provider
Hell 2 Heaven or Choosing Cloud ProviderUP2IT
 
Automation pyramid within CI process
Automation pyramid within CI processAutomation pyramid within CI process
Automation pyramid within CI processUP2IT
 
Containers, containers, containers...
Containers, containers, containers...Containers, containers, containers...
Containers, containers, containers...UP2IT
 
Kotlin для розробки Android
Kotlin для розробки AndroidKotlin для розробки Android
Kotlin для розробки AndroidUP2IT
 
React. Learn once, write anywhere
React. Learn once, write anywhereReact. Learn once, write anywhere
React. Learn once, write anywhereUP2IT
 
Сложности и специфика построения систем раздачи адалт видео контента
Сложности и специфика построения систем раздачи адалт видео контентаСложности и специфика построения систем раздачи адалт видео контента
Сложности и специфика построения систем раздачи адалт видео контентаUP2IT
 
H2H Communication in IT
H2H Communication in ITH2H Communication in IT
H2H Communication in ITUP2IT
 
Как я не стал барабанщиком или Как менеджер создает ценность
Как я не стал барабанщиком или Как менеджер создает ценностьКак я не стал барабанщиком или Как менеджер создает ценность
Как я не стал барабанщиком или Как менеджер создает ценностьUP2IT
 
Epic Sales Fails Compilation
Epic Sales Fails CompilationEpic Sales Fails Compilation
Epic Sales Fails CompilationUP2IT
 
Design Thinking
Design ThinkingDesign Thinking
Design ThinkingUP2IT
 
Как настроенные процессы повышают прибыльность и снижают стресс
Как настроенные процессы повышают прибыльность и снижают стрессКак настроенные процессы повышают прибыльность и снижают стресс
Как настроенные процессы повышают прибыльность и снижают стрессUP2IT
 

More from UP2IT (18)

Microservices. Mastering Chaos
Microservices. Mastering ChaosMicroservices. Mastering Chaos
Microservices. Mastering Chaos
 
Сочетание классической и гибкой методологий управления проектами
Сочетание классической и гибкой методологий управления проектамиСочетание классической и гибкой методологий управления проектами
Сочетание классической и гибкой методологий управления проектами
 
Go для веба глазами PHP-разработчика
Go для веба глазами PHP-разработчикаGo для веба глазами PHP-разработчика
Go для веба глазами PHP-разработчика
 
Дизайнер в эпоху цифровых перемен
Дизайнер в эпоху цифровых переменДизайнер в эпоху цифровых перемен
Дизайнер в эпоху цифровых перемен
 
Продуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктів
Продуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктівПродуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктів
Продуктовий дизайн і UX / UI дизайн процеси при розробці цифрових продуктів
 
Модели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITION
Модели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITIONМодели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITION
Модели OPEN SOURCE компаний и можно ли выжить без OPEN CORE и ENTERPRISE EDITION
 
VR/AR в бизнесе
VR/AR в бизнесеVR/AR в бизнесе
VR/AR в бизнесе
 
Hell 2 Heaven or Choosing Cloud Provider
Hell 2 Heaven or Choosing Cloud ProviderHell 2 Heaven or Choosing Cloud Provider
Hell 2 Heaven or Choosing Cloud Provider
 
Automation pyramid within CI process
Automation pyramid within CI processAutomation pyramid within CI process
Automation pyramid within CI process
 
Containers, containers, containers...
Containers, containers, containers...Containers, containers, containers...
Containers, containers, containers...
 
Kotlin для розробки Android
Kotlin для розробки AndroidKotlin для розробки Android
Kotlin для розробки Android
 
React. Learn once, write anywhere
React. Learn once, write anywhereReact. Learn once, write anywhere
React. Learn once, write anywhere
 
Сложности и специфика построения систем раздачи адалт видео контента
Сложности и специфика построения систем раздачи адалт видео контентаСложности и специфика построения систем раздачи адалт видео контента
Сложности и специфика построения систем раздачи адалт видео контента
 
H2H Communication in IT
H2H Communication in ITH2H Communication in IT
H2H Communication in IT
 
Как я не стал барабанщиком или Как менеджер создает ценность
Как я не стал барабанщиком или Как менеджер создает ценностьКак я не стал барабанщиком или Как менеджер создает ценность
Как я не стал барабанщиком или Как менеджер создает ценность
 
Epic Sales Fails Compilation
Epic Sales Fails CompilationEpic Sales Fails Compilation
Epic Sales Fails Compilation
 
Design Thinking
Design ThinkingDesign Thinking
Design Thinking
 
Как настроенные процессы повышают прибыльность и снижают стресс
Как настроенные процессы повышают прибыльность и снижают стрессКак настроенные процессы повышают прибыльность и снижают стресс
Как настроенные процессы повышают прибыльность и снижают стресс
 

Recently uploaded

NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)Basil Achie
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxJohnree4
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...NETWAYS
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸mathanramanathan2005
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...marjmae69
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxaryanv1753
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 

Recently uploaded (20)

NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptx
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptx
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 

Native DB transactions

  • 2. Sails.js ● MVC web application framework inspired by Ruby on Rails ● Built on Node.js and Express.js ● Delivered with Waterline ORM containing a set of adapters to various databases
  • 3. The problem Request context There is no ability to get the current request/ user/session in any application place. Because of async nature of the JS they should be passed as function arguments. Random DB connection DB adapter uses only one connection for each request or random from pool (if pool mode is on). Error handling In case of uncatched exception there is no chance to figure to whom the response should be sent to.
  • 4. Domain API var domain = require('domain'); domain = domain.create(); const net = require('net'); net.createServer((req, res) => { domain.run(() => { setImmediate(() => { let active = require('domain').active; res.write('bye'); res.end(); }); }); }).listen(8000);
  • 5. The solution Request identification Generate and assign uuid for each incoming request. Store request with its id to domain in the middleware. DB adapter Take request from the domain context and use dedicated DB connection for each request. Finalize request Commit or rollback transaction and return connection to the pool.
  • 6. Express middleware Create domain, set request to the domain, start the transaction Custom DB adapter Checks current domain and uses dedicated connection. Single transaction for the whole request lifecycle Business logic Has access and can store data to its own request context Single response point Finish transaction and release connection