Written by: Ismaël Diakité
Date Published: 31 December 2023
Introduction
In the world of Azure Active Directory (AAD), managing and retrieving group information efficiently is crucial for the performance and scalability of applications. This article delves into a comparative analysis of two popular methods for fetching group data from AAD - using the Microsoft Graph SDK and direct REST API calls. The benchmarking is based on a dataset of 10,000 groups, providing a real-world scenario for performance evaluation.
Experiment Setup
Objective: To compare the performance of Microsoft Graph SDK with direct REST API calls for fetching large volumes of group data from Azure AD.
Environment:
- Hardware: Intel Core i9-10885H CPU, 16 logical and 8 physical cores
- Operating System: Windows 11
- Development Environment: .NET SDK 8.0.100
- Benchmarking Tool: BenchmarkDotNet v0.13.11
- Dataset: 10,000 groups in Azure AD, created using a script that posts groups asynchronously to Azure AD using Microsoft Graph SDK.
async Task CreateGroupsAsync(GraphServiceClient graphClient)
{
var tasks = new List<Task>();
for (int i = 0; i < 10000; i++)
{
var groupName = $"group-test-{Guid.NewGuid()}";
var group = new Group
{
DisplayName = groupName,
MailEnabled = false,
MailNickname = groupName,
SecurityEnabled = true
};
tasks.Add(graphClient.Groups.PostAsync(group));
}
await Task.WhenAll(tasks);
}
Methodology: Two methods were benchmarked:
- GetGroupsUsingMicrosoftSdkAsyncBenchmark: Fetching groups using Microsoft Graph SDK with paging.
- GetGroupsUsingMicrosoftRestApiAsyncBenchmark: Fetching groups using the Microsoft REST API with paging.
Results
Method | Mean Time | Error | StdDev |
---|---|---|---|
GetGroupsUsingMicrosoftSdkAsyncBenchmark | 10.830 s | 0.2726 s | 0.7995 s |
GetGroupsUsingMicrosoftRestApiAsyncBenchmark | 5.871 s | 0.1163 s | 0.3356 s |
Interpretation
- The REST API method (GetGroupsUsingMicrosoftRestApiAsyncBenchmark) outperformed the SDK method, completing the task in nearly half the time.
- The SDK approach, while more user-friendly and abstracted, incurred additional overhead leading to longer execution times.
Analysis
- Performance: The direct REST API approach provided a significant performance advantage. This can be attributed to lower-level control over network requests and the ability to optimize them.
- Ease of Use: The SDK approach simplifies the process with higher-level abstractions, which is beneficial for rapid development and reduces the likelihood of errors.
- Scalability: For applications dealing with large datasets, the REST API method shows better scalability.
- Practical Application: The choice between these methods should consider both the scale of data and the development context. For large-scale operations where performance is critical, the REST API is more suitable. In contrast, for smaller scales or where ease of development is a priority, the SDK approach is advantageous.
Conclusion
The benchmarking exercise clearly demonstrates the trade-offs between using the Microsoft Graph SDK and the direct REST API for data retrieval in Azure AD. While the SDK offers ease of use, the REST API leads in performance, especially in scenarios involving large datasets. Developers should weigh these factors based on their specific requirements and constraints.
Recommendations
- For Large-Scale Applications: Consider using the REST API for its performance benefits.
- For Rapid Development and Smaller Applications: The SDK is a preferable choice for its simplicity and reduced development time.
Full Source Code
The complete source code for this project can be found at the following GitHub repository: BenchmarkMicrosoftGraphSdkAndApi