Skip to content

Commit 2cef5aa

Browse files
authored
Merge pull request #10438 from MicrosoftDocs/jdaly-main-auto-numbering
Add note to auto-numbering scenario
2 parents fbc7aad + 081b39d commit 2cef5aa

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

powerapps-docs/developer/data-platform/scalable-customization-design/auto-numbering-example.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
---
2-
title: "Scalable Customization Design: Auto-numbering example (Microsoft Dataverse) | Microsoft Docs"
2+
title: "Scalable Customization Design: Autonumbering example (Microsoft Dataverse) | Microsoft Docs"
33
description: "This example illustrates how transactions and concurrency issues need to be accounted for in a code customization."
4-
ms.date: 04/23/2024
4+
ms.date: 09/06/2024
55
ms.reviewer: pehecke
66
ms.topic: article
77
author: rogergilchrist
8-
ms.author: jdaly # MSFT alias of Microsoft employees only
8+
ms.author: rogergil
99
search.audienceType:
1010
- developer
11+
contributors:
12+
-JimDaly
1113
---
12-
# Scalable Customization Design: Auto-numbering example
14+
# Scalable Customization Design: Autonumbering example
1315

1416

1517

1618
> [!NOTE]
1719
> This example supports a series of topics about scalable customization design. To start at the beginning, see [Scalable Customization Design in Microsoft Dataverse](overview.md).
20+
>
21+
> Dataverse has an [Autonumber columns](../../../maker/data-platform/autonumber-fields.md) feature you should use if it meets your requirements.
22+
>
23+
> This article describes how to manage transactions effectively to ensure a solution can handle growth, using the example of autonumbering. It outlines a process of trying, testing, and evaluating different approaches. While the third approach improves upon the first two, it might not be perfect for every situation. Therefore, it's crucial to thoroughly test any developed solution, as you are responsible for maintaining your own code.
24+
1825

1926
One scenario that illustrates the common misunderstanding of how transactions are handled within Dataverse is implementing an automatic numbering scheme.
2027

@@ -37,12 +44,12 @@ The following sections describe different approaches that can be taken within Da
3744

3845
## Approach 1: Out of a transaction
3946

40-
The simplest approach is to realize that any use of a commonly required resource would introduce the potential for blocking. Since this has an impact on scalability, you might decide you want to avoid a platform transaction when generating an auto number.
47+
The simplest approach is to realize that any use of a commonly required resource would introduce the potential for blocking. Since blocking has an impact on scalability, you might decide you want to avoid a platform transaction when generating an auto number.
4148
Let's consider the scenario for auto numbering generation outside of the pipeline transaction in a pre-validation plug-in.
4249

4350
![Approach 1: Out of a transaction.](media/autonumber-approach-1.png)
4451

45-
When you run this in isolation it works fine. It doesn't, however, actually protect against concurrency errors. As the following diagram shows, if two requests in parallel both request the latest number and then both increment and update the value, you end up with duplicate numbers. Because there's no locking held against the retrieved number, it's possible for a race condition to occur and both threads to end up with the same value.
52+
When you run this in isolation, it works fine. It doesn't, however, actually protect against concurrency errors. As the following diagram shows, if two requests in parallel both request the latest number and then both increment and update the value, you end up with duplicate numbers. Because there's no locking held against the retrieved number, it's possible for a race condition to occur and both threads to end up with the same value.
4653

4754
![race condition.](media/autonumber-approach-1-a.png)
4855

@@ -84,7 +91,7 @@ Normally, generation of the auto number would be done in a pre-event plug-in. Yo
8491

8592
With the scalability implications in mind, if there's other complex processing in the account creation process, an alternative would be to move the auto number generation to a post create process, which still ensures a consistent update process. The benefit would be that it reduces the length of time within the transaction that the auto number record lock is held as the lock is only taken towards the end of the process. If the auto numbering table is the most highly contested resource and this approach is taken for all processes accessing it, this reduces the amount of contention overall.
8693

87-
The tradeoff here would be the need to perform an additional update to account, while reducing the overall length of time blocking waiting for the auto numbering record.
94+
The tradeoff here would be the need to perform an another update to account, while reducing the overall length of time blocking waiting for the auto numbering record.
8895

8996
![move the auto number generation to a post create process.](media/autonumber-approach-3-b.png)
9097

0 commit comments

Comments
 (0)