504 Gateway Time-out when Getting B2C Users List (80K) using MS Graph in Asp Dot Net core WebApp

Rishi Verma 126 Reputation points
2021-04-14T12:44:31.377+00:00

Hello All,
I am getting 504 Gateway Time-out Error when fetching B2C Users List which is >80K. The same worked fine for around 4k users, with a little wait, and works even more smooth with less than 2k users while testing.

Is there any suggestion to handle such huge Users List? Code snippet is below:

      public async Task<List<User>> GetAllUsers()  
    {  

        List<User> userResult = new List<User>();  
        UsersModel signin = new UsersModel();  
          
        var graphClient = await GetGraphServiceClientAsync();  
        var users = await graphClient.Users.Request().Top(999).Select(e => new  
        {  
            e.DisplayName,  
            e.CreatedDateTime,  
            e.Id,  
            e.Identities,  
            e.UserPrincipalName,  
            e.OtherMails,  
            e.Mail  
        }  
        ).GetAsync().ConfigureAwait(true);  

        userResult.AddRange(users.CurrentPage.OrderBy(e=>e.CreatedDateTime));  

        while(users.NextPageRequest!=null)  
        {  
            users = await users.NextPageRequest.GetAsync();  
            userResult.AddRange(users.CurrentPage.OrderBy(e=>e.CreatedDateTime));                 
        }  
        return userResult;  
    }  

87831-image.png

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,212 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,734 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,663 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee
    2021-04-17T10:09:44.433+00:00
    • Try with smaller pagination and see if it helps
    • When you see failure see if you can re-try the same API and if it succeeds or not
    • Outside of your code, can you repro the issue with Microsoft Graph Explorer/POSTMAN as well?
    0 comments No comments