You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: powerapps-docs/developer/data-platform/scalable-customization-design/auto-numbering-example.md
+14-7Lines changed: 14 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,27 @@
1
1
---
2
-
title: "Scalable Customization Design: Auto-numbering example (Microsoft Dataverse) | Microsoft Docs"
2
+
title: "Scalable Customization Design: Autonumbering example (Microsoft Dataverse) | Microsoft Docs"
3
3
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
5
5
ms.reviewer: pehecke
6
6
ms.topic: article
7
7
author: rogergilchrist
8
-
ms.author: jdaly # MSFT alias of Microsoft employees only
8
+
ms.author: rogergil
9
9
search.audienceType:
10
10
- developer
11
+
contributors:
12
+
-JimDaly
11
13
---
12
-
# Scalable Customization Design: Auto-numbering example
14
+
# Scalable Customization Design: Autonumbering example
13
15
14
16
15
17
16
18
> [!NOTE]
17
19
> 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
+
18
25
19
26
One scenario that illustrates the common misunderstanding of how transactions are handled within Dataverse is implementing an automatic numbering scheme.
20
27
@@ -37,12 +44,12 @@ The following sections describe different approaches that can be taken within Da
37
44
38
45
## Approach 1: Out of a transaction
39
46
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.
41
48
Let's consider the scenario for auto numbering generation outside of the pipeline transaction in a pre-validation plug-in.
42
49
43
50

44
51
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.
@@ -84,7 +91,7 @@ Normally, generation of the auto number would be done in a pre-event plug-in. Yo
84
91
85
92
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.
86
93
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.
88
95
89
96

0 commit comments