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

Developer technologies ASP.NET ASP.NET Core
Microsoft Security Microsoft Entra Microsoft Entra External ID
Microsoft Security Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Deva-MSFT 2,271 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.