{"id":10528,"date":"2021-02-24T04:24:41","date_gmt":"2021-02-24T12:24:41","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=10528"},"modified":"2025-06-13T23:42:26","modified_gmt":"2025-06-14T06:42:26","slug":"use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/","title":{"rendered":"Use cases and Best Practices for Distributed Transactions through N1QL"},"content":{"rendered":"<p><b>Does Couchbase support transactions?<\/b><\/p>\n<p><b>Yes! <\/b><span style=\"font-weight: 400\">With 6.5, we introduced the <a href=\"https:\/\/www.couchbase.com\/transactions\/\">ACID transaction<\/a> support in Couchbase through the SDKs. The 1<\/span><span style=\"font-weight: 400\">st<\/span><span style=\"font-weight: 400\"> question we got at the time from the customers that heard about it was:<\/span><\/p>\n<p><b><i>Is transaction support available through N1QL?<\/i><\/b><\/p>\n<p><b>Yes! <\/b><span style=\"font-weight: 400\">With 7.0, we have started supporting transactions through N1QL as well!<strong>N1QL transactions are multi-everything. Multi-documents that can span multiple collections from multiple scopes within multiple buckets. You can have multiple transactions running on a single query node and you can have multiple query nodes. There is NO central coordinator thereby eliminating a single point of failure or contention and making way for infinite scalability!<\/strong><\/span><\/p>\n<p><b><i>What is N1QL? and Why is it so important for Couchbase?<\/i><\/b><\/p>\n<p><span style=\"font-weight: 400\">Just like SQL is to RDBMS, N1QL is to Couchbase!<\/span><\/p>\n<p><a href=\"https:\/\/docs.couchbase.com\/server\/current\/getting-started\/try-a-query.html\"><span style=\"font-weight: 400\">N1QL<\/span><\/a><span style=\"font-weight: 400\"> is a declarative language-almost identical to SQL and it is used to insert\/retrieve and manipulate the data stored in the form of JSON documents.<\/span><span style=\"font-weight: 400\">Learn more about N1QL <\/span><a href=\"https:\/\/query-tutorial.couchbase.com\/tutorial\/#1\"><span style=\"font-weight: 400\">here<\/span><\/a><span style=\"font-weight: 400\"> .<\/span><\/p>\n<p><b><i>If N1QL is like SQL, then why did it not have ACID before?<\/i><\/b><\/p>\n<p><span style=\"font-weight: 400\">N1QL always had ACID within a single document. What we did not have before 7.0 was Multi-document Transaction support through N1QL.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Well, let\u2019s think first about why many people believe they need multi-document transactions. The first principle of relational data modeling is normalizing your data across tables. This means that many common database operations, like account creation, require atomic updates across many rows and columns.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In Couchbase, the data model is fundamentally different. The document model encourages users to store related data together in a single document. N1QL has always supported ACID transactions in a single document and, when leveraging the document model appropriately, many applications don\u2019t need ACID guarantees across multiple documents. As shown below, data that needs to be stored in 3 different tables tied by PK-FK, gets stored in a single document in Couchbase.\u00a0\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10803 aligncenter\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-300x171.png\" alt=\"\" width=\"805\" height=\"459\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-300x171.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-1024x583.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-768x437.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-1536x874.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-2048x1165.png 2048w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-20x11.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-02-16-at-10.52.23-AM-1320x751.png 1320w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><\/p>\n<p><span style=\"font-weight: 400\">For e.g. Adding an item to a shopping cart <\/span><span style=\"font-weight: 400\">does not need transactions in Couchbase as you are updating just a single document<\/span><\/p>\n<p><span style=\"font-weight: 400\">However, transactions are not just a check box. Transactions, like every Couchbase feature, aim to make developers\u2019 lives easier. ACID guarantees across documents simplify the application logic needed to satisfy complex applications.<\/span><\/p>\n<h4><b><i>What are the Use Cases for Multi-Document transactions?<\/i><\/b><b><i>:<\/i><\/b><\/h4>\n<p><span style=\"font-weight: 400\">There are use cases where transactional ACID guarantees need to be applied to a set of operations that span multiple documents.\u00a0 \u201cSystem of Record\u201d applications are the typical class of workload where multi-document transactions are useful. Examples include:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Processing application events when users perform actions that if repeated may cause different results, so they have to either all succeed or all fail. For e.g. typical bank debit, credit.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Logging custom application actions \u2013that cannot be reverted back even in case of system failure, say when a user transfers ownership of a car or a house, the write should not be successful if the logging isn\u2019t.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Many to many relationships where the data naturally fit into defined objects \u2014 for example, Clients, client orders, products, and manufacturers. To calculate the total in a client order, values from each table need to be collected and summed up for every client.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">\u00a0<\/span><\/p>\n<h4><b>Details about transactions through N1QL in Couchbase:<\/b><\/h4>\n<p><span style=\"font-weight: 400\">Let\u2019s dive into N1QL transactions with a simple transaction, debit, and credit. Selects have to read their own updates (RYOW)<\/span><\/p>\n<p><b>START TRANSACTION;<\/b><\/p>\n<p><b>UPDATE customer SET balance = balance \u2013 100 WHERE cid = 4872;<\/b><\/p>\n<p><b>UPDATE customer SET balance = balance + 100 WHERE cid = 1924;<\/b><\/p>\n<p><b>SELECT cid, name, balance from customer where cid in [4872,1924];<\/b><\/p>\n<p><b>COMMIT ;<\/b><\/p>\n<p>This is the same syntax as you would write in MySQL. That\u2019s the beauty of N1QL.<\/p>\n<p><span style=\"font-weight: 400\">You don\u2019t have to learn a new language to use Couchbase if you are already familiar with SQL.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In the example above,<\/span><\/p>\n<p><span style=\"font-weight: 400\">If you are already familiar with the architecture of Couchbase, then<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">START TRANSACTION will go to a query node. Query node will assign a unique transaction id (txid) to this transaction.<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10804 aligncenter\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-300x95.png\" alt=\"\" width=\"900\" height=\"285\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-300x95.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-1024x325.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-768x244.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-1536x488.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-2048x650.png 2048w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-20x6.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.54.03-PM-1320x419.png 1320w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Next comes the update statement. Query node will look at the where clause, select the appropriate index that will serve the query, find the document id, send the document id to the data store(KV) and fetch the document into the query node and then update the balance. If this was not within a transaction, this would be sent back to the datastore immediately. But since it is within the transaction, this document will now be stored in the cache of the query node. This cache we refer to as the delta table. We have 1 delta table per transaction per collection. That\u2019s why we need all statements of a transaction to come to the same query node. This stitching is done with the txid provided by START TRANSACTION.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">With the next update, same thing, Query node will look at the where clause, select the appropriate index that will serve the query, find the document id, but now instead of directly going to KV to fetch the document, since there is a delta table, it will first look in the delta table if this document already exists in the delta table. In this case, it doesn\u2019t so it goes fetches from KV, updates the balance, and stores it in the delta table.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Next comes the select statement to the query node. Again query node will look at the where clause, select the appropriate index that will serve the query, find the document id. Now it will look for the document ids in the delta table, find them there and send the projected fields back to the client.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10844 aligncenter\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-300x91.png\" alt=\"\" width=\"797\" height=\"242\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-300x91.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-1024x312.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-768x234.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-1536x468.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-20x6.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM-1320x402.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/02\/Screen-Shot-2021-01-30-at-2.48.49-PM.png 1774w\" sizes=\"auto, (max-width: 797px) 100vw, 797px\" \/><\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">So far you see we have read from the data store but never written to the data store. We have only written to the cache in the query node. And hence we say we follow optimistic concurrency. Multiple transactions could be operating on these very same documents at the same time.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Now when the next statement hits the Query node \u201cCOMMIT\u201d, that\u2019s when the updated documents will go to the KV node and we will use the commit protocol highlighted <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-transactions-java-api\/.\"><span style=\"font-weight: 400\">here<\/span><\/a><span style=\"font-weight: 400\"> to actually commit the changes.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">At this point, if there were multiple transactions updating the same documents, one would succeed and others would rollback and have to retry.<\/span><\/li>\n<\/ul>\n<h4><b><i>N1QL transaction Best Practices :<\/i><\/b><\/h4>\n<h5><b>When should you use N1QL transactions?<\/b><\/h5>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">When you have multiple query statements that should either all go through or all fail.A typical example: debit credit, multi-leg airline reservation<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">If you want to make sure that changes once made are not reverted back even in case of a system crash, like transfer of title for a house\/car.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">When the logic required spans data that cannot be merged into a single document and requires updates to multiple documents.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Typically very short-running workloads involving small result sets-no major aggregates.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">When you might need to modify\/read the same documents over and over again\u00a0 (supported by Read your own writes by using delta tables)<\/span><\/li>\n<\/ol>\n<h5><b><i>What should you avoid doing while using N1QL transactions?<\/i><\/b><\/h5>\n<p><span style=\"font-weight: 400\">From even as simple example above you can probably see that:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Delta table (which is per transaction\/per collection) will grow with every mutation. If you have a transaction, with a lot of mutations, memory usage will increase. So the recommendation is to limit the number of mutations within a transaction. For ETL-like loads, or massive updates that need ACID guarantees we have provided another option of Implicit transactions. You can read about them <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/7.0\/settings\/query-settings.html#tximplicit\"><span style=\"font-weight: 400\">here<\/span><\/a><span style=\"font-weight: 400\">.\u201cmemory-quota\u201d setting in the query service can control the amount of memory consumed by the delta tables.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Use transactions only on documents less than 10MB in size.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Do not include <\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_definition_language\"><span style=\"font-weight: 400\">DDL operations<\/span><\/a><span style=\"font-weight: 400\"> within N1QL transactions. Any DDL operations will result in an error.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">By default, the timeout is 15s. This can be modified depending on the means you are using to use N1QL transactions(cbq shell, UI, Java SDK or REST API)<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The query service was designed to provide high throughput and low latency, both of which can be impacted with transactions. Use N1QL transactions when your use cases have the need for transactions.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Since we use optimistic concurrency, we have to be sure that most of our workload is such that multiple transactions are not modifying the same documents at the same time. Because in that case, one will succeed and others will rollback with \u201cCAS mismatch\u201d or \u201cWrite write conflict\u201d errors.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">We should not be modifying the same documents using transactions and non-transactions at the same time.<\/span><\/li>\n<\/ol>\n<p>Understand how transactions work by using the <a href=\"https:\/\/transactions.couchbase.com\/\">Transactions simulator<\/a><\/p>\n<p><span style=\"font-weight: 400\">More about Transactions support through N1QL<\/span><\/p>\n<p><a href=\"https:\/\/www.couchbase.com\/blog\/transactions-n1ql-couchbase-distributed-nosql\/\"><span style=\"font-weight: 400\">https:\/\/www.couchbase.com\/blog\/transactions-n1ql-couchbase-distributed-nosql\/<\/span><\/a><\/p>\n<p><a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-transactions-with-n1ql\/\"><span style=\"font-weight: 400\">https:\/\/www.couchbase.com\/blog\/couchbase-transactions-with-n1ql\/<\/span><\/a><\/p>\n<p><a href=\"https:\/\/docs.couchbase.com\/java-sdk\/current\/howtos\/distributed-acid-transactions-from-the-sdk.html#n1ql-queries\"><span style=\"font-weight: 400\">https:\/\/docs.couchbase.com\/java-sdk\/current\/howtos\/distributed-acid-transactions-from-the-sdk.html#n1ql-queries<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Does Couchbase support transactions? Yes! With 6.5, we introduced the ACID transaction support in Couchbase through the SDKs. The 1st question we got at the time from the customers that heard about it was: Is transaction support available through N1QL? [&hellip;]<\/p>\n","protected":false},"author":50908,"featured_media":10545,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,2225,1816,1812,2396],"tags":[9499,8191,1725,2221],"ppma_author":[9099],"class_list":["post-10528","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-cloud","category-couchbase-server","category-n1ql-query","category-transactions","tag-acid-transactions","tag-distributed-transactions","tag-nosql-database","tag-transactions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Use cases and Best Practices for Distributed Transactions through N1QL - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Typical use cases and Best Practices for using the newly introduced distributed transactions through N1QL in Couhbase!What to do and what to avoid doing!?\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use cases and Best Practices for Distributed Transactions through N1QL\" \/>\n<meta property=\"og:description\" content=\"Typical use cases and Best Practices for using the newly introduced distributed transactions through N1QL in Couhbase!What to do and what to avoid doing!?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-24T12:24:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T06:42:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"3359\" \/>\n\t<meta property=\"og:image:height\" content=\"1565\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Kamini Jagtiani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kamini Jagtiani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\"},\"author\":{\"name\":\"Kamini Jagtiani\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f99c5767a877147f9cf658230bc2473b\"},\"headline\":\"Use cases and Best Practices for Distributed Transactions through N1QL\",\"datePublished\":\"2021-02-24T12:24:41+00:00\",\"dateModified\":\"2025-06-14T06:42:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\"},\"wordCount\":1464,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png\",\"keywords\":[\"ACID transactions\",\"distributed transactions\",\"NoSQL Database\",\"transactions\"],\"articleSection\":[\"Best Practices and Tutorials\",\"Couchbase Capella\",\"Couchbase Server\",\"SQL++ \/ N1QL Query\",\"Transactions\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\",\"name\":\"Use cases and Best Practices for Distributed Transactions through N1QL - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png\",\"datePublished\":\"2021-02-24T12:24:41+00:00\",\"dateModified\":\"2025-06-14T06:42:26+00:00\",\"description\":\"Typical use cases and Best Practices for using the newly introduced distributed transactions through N1QL in Couhbase!What to do and what to avoid doing!?\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png\",\"width\":3359,\"height\":1565},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use cases and Best Practices for Distributed Transactions through N1QL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f99c5767a877147f9cf658230bc2473b\",\"name\":\"Kamini Jagtiani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/257695296726c224fc7f0e85b30c9129\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/546f9f69203064f77430f14922d59be33e3f0ea674078a793fc813dd40310c5c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/546f9f69203064f77430f14922d59be33e3f0ea674078a793fc813dd40310c5c?s=96&d=mm&r=g\",\"caption\":\"Kamini Jagtiani\"},\"description\":\"Kamini Jagtiani is a Senior Engineering Manager for the Query Team at Couchbase R&amp;D. Before Couchbase, Kamini was 7 years at Futurewei as Kernel Architect\/Manager and 13 years at IBM Informix as Software Engineer. Kamini has a Bachelors's degree in Computer Science and Engineering from Bombay University, India and holds 5 US patents.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/kaminijagtiani\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Use cases and Best Practices for Distributed Transactions through N1QL - The Couchbase Blog","description":"Typical use cases and Best Practices for using the newly introduced distributed transactions through N1QL in Couhbase!What to do and what to avoid doing!?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/","og_locale":"en_US","og_type":"article","og_title":"Use cases and Best Practices for Distributed Transactions through N1QL","og_description":"Typical use cases and Best Practices for using the newly introduced distributed transactions through N1QL in Couhbase!What to do and what to avoid doing!?","og_url":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-02-24T12:24:41+00:00","article_modified_time":"2025-06-14T06:42:26+00:00","og_image":[{"width":3359,"height":1565,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png","type":"image\/png"}],"author":"Kamini Jagtiani","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kamini Jagtiani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/"},"author":{"name":"Kamini Jagtiani","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f99c5767a877147f9cf658230bc2473b"},"headline":"Use cases and Best Practices for Distributed Transactions through N1QL","datePublished":"2021-02-24T12:24:41+00:00","dateModified":"2025-06-14T06:42:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/"},"wordCount":1464,"commentCount":1,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png","keywords":["ACID transactions","distributed transactions","NoSQL Database","transactions"],"articleSection":["Best Practices and Tutorials","Couchbase Capella","Couchbase Server","SQL++ \/ N1QL Query","Transactions"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/","url":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/","name":"Use cases and Best Practices for Distributed Transactions through N1QL - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png","datePublished":"2021-02-24T12:24:41+00:00","dateModified":"2025-06-14T06:42:26+00:00","description":"Typical use cases and Best Practices for using the newly introduced distributed transactions through N1QL in Couhbase!What to do and what to avoid doing!?","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/01\/Screen-Shot-2021-01-31-at-12.46.45-AM.png","width":3359,"height":1565},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/use-cases-and-best-practices-to-use-distributed-transactions-in-n1ql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Use cases and Best Practices for Distributed Transactions through N1QL"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f99c5767a877147f9cf658230bc2473b","name":"Kamini Jagtiani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/257695296726c224fc7f0e85b30c9129","url":"https:\/\/secure.gravatar.com\/avatar\/546f9f69203064f77430f14922d59be33e3f0ea674078a793fc813dd40310c5c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/546f9f69203064f77430f14922d59be33e3f0ea674078a793fc813dd40310c5c?s=96&d=mm&r=g","caption":"Kamini Jagtiani"},"description":"Kamini Jagtiani is a Senior Engineering Manager for the Query Team at Couchbase R&amp;D. Before Couchbase, Kamini was 7 years at Futurewei as Kernel Architect\/Manager and 13 years at IBM Informix as Software Engineer. Kamini has a Bachelors's degree in Computer Science and Engineering from Bombay University, India and holds 5 US patents.","url":"https:\/\/www.couchbase.com\/blog\/author\/kaminijagtiani\/"}]}},"authors":[{"term_id":9099,"user_id":50908,"is_guest":0,"slug":"kaminijagtiani","display_name":"Kamini Jagtiani","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/546f9f69203064f77430f14922d59be33e3f0ea674078a793fc813dd40310c5c?s=96&d=mm&r=g","author_category":"","last_name":"Jagtiani","first_name":"Kamini","job_title":"","user_url":"","description":"Kamini Jagtiani is a Senior Engineering Manager for the Query Team at Couchbase R&amp;D. Before Couchbase, Kamini was 7 years at Futurewei as Kernel Architect\/Manager and 13 years at IBM Informix as Software Engineer. Kamini has a Bachelors's degree in Computer Science and Engineering from Bombay University, India and holds 5 US patents."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/10528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/50908"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=10528"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/10528\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/10545"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=10528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=10528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=10528"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=10528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}