High Performance Batching and Sequencing Operations
A major advantage with stored procedures is that they enable applications to perform complex batches and sequences of operations directly inside the database engine, closer to the data. Developers can group and sequence operations (like inserts, updates, or deletes) and submit them together. The benefit here is that the network traffic latency costs for batching and sequencing operations can completely avoided.
A sequence of database operations
A sequence of operations using Stored Procedures
DocumentDB offers full ACID (Atomicity, Consistency, Isolation, and Durability) guarantees for all operations that take part of a single stored procedure. In other words, stored procedures enable applications to combine related operations in a single batch so that either all of them succeed or none of them succeed. This is notable, because few NoSQL databases provide ACID transactions across multiple documents / records.
It’s important to note that stored procedures have bounded execution, in which all operations must complete within the server specified request timeout duration. If an operation does not complete with that time limit, the transaction is automatically rolled back. In order to simplify development to handle time limits, all CRUD (Create, Read, Update, and Delete) operations return a Boolean value that represents whether that operation will complete. This Boolean value can be used a signal to wrap up execution and for implementing a continuation based model to resume execution (this is illustrated in our code samples below).
Video Walkthrough, Code Samples, and More!
Can’t wait to get started? We’ve prepared a brief 5-minute video to walking you through the creation and execution of a stored procedure, available on Channel 9.
To learn how to get started with DocumentDB or for more information, please check out our website. For more information regarding DocumentDB’s server-side programming model, check out our documentation here.