Round-robin for task assignment - similar to call-center load balancing

I have a use-case where there are “N” users on my app and “NN” tasks which are inputs to the app. I would like to implement a round-robin type of task assignment in the app so each of the N users gets an equal amount of tasks. You could almost think of it as a load-balancer for a call-center, spreading the calls (emails in my case) evenly to support staff.

For example, say there are 5 users on the app and there are 30 support emails on any given day. I’d like to balance those 30 emails so by the end of the day, each user will have gotten 6 emails.

Anyone have a slick way of implementing something like this in bubble? Thanks in advance.


Hey @nikolai, if you get these tasks one at a time, then you can keep track of how many tasks each user has (using a data field on the User object), and then each time you get a new task, you can assign it to the user with the fewest tasks. You can accomplish this by doing a search for users, sorted by number of tasks in ascending order. At the beginning everyone has 0 tasks so it will just pick someone, but that person will then be at the end of the list for the next task so you’ll always ensure that nobody gets ahead by more than one.

It’s a different story if you want to assign a bunch of tasks all at once…


1 Like

Hi @nikolai :slight_smile: I’ve tried to setup something similar before, and I think the ‘modulo’ operator might be helpful too! For example, in this repeating group I have 30 Support Email Things, and each of them have a number (1 through 30):

Editor: faye-demo-app | Bubble Editor


This repeating group does a Search for Support Emails, and then uses conditional formatting to change the color of each cell, so that they are separated into 6 different groups (or colors):

In this expression, we’re using <-modulo->6 because there are 6 groups. If we only had 5 we would change each expression to <-modulo->5. I’m not 100% sure about how to explain modulo, but my understanding is that modulo always gives you the remainder. So for the first 8 Support Emails, the expressions mean:

  1. 1<-modulo->6 is 1 (The remainder of 1 divided by 6 is 1)
  2. 2<-modulo->6 is 2 (The remainder of 2 divided by 6 is 2)
  3. 3<-modulo->6 is 3 (The remainder of 3 divided by 6 is 3)
  4. 4<-modulo->6 is 4 (The remainder of 4 divided by 6 is 4)
  5. 5<-modulo->6 is 5 (The remainder of 5 divided by 6 is 5)
  6. 6<-modulo->6 is 0 (The remainder of 6 divided by 6 is 0)
  7. 7<-modulo->6 is 1 (The remainder of 7 divided by 6 is 1)
  8. 8<-modulo->6 is 2 (The remainder of 8 divided by 6 is 2)
    (and this repeats for all 30)

If you don’t store each Support Email in the database on a User, you can use an advanced constraint to filter them into individual groups:

(Note: If a User has a Group Number (1 through 6), the expression would be: "Advanced: This SupportEmail’s Number <-modulo-> 6 is Current User’s Group Number).

If you are creating the Support Emails one by one over the course of the day, each of those would be assigned a number (1 through 30) as they are created using “Ticket Number = Search for SupportEmails:count + 1”.

Then you can assign each Support Email a Group Number (to put them into one of the six groups evenly), using the expression: Group Number = “Search for SupportEmails:count+1<-modulo-> 6”. The result of that expression will assign it to either 1, 2, 3, 4, 5, or 0.

If you want to assign all of the Support Emails a Group Number at one time, you can use the “Make Changes to a List of Things” action, and set the Group Number in the same way using “Group Number = This Support Email’s ticket number <-modulo->6” to get a result of 1,2,3,4,5 or 0.

Then, the Users in your app can have a corresponding Group Number field (1,2,3,4,5 or 6). You can query the corresponding Support Emails (which match the User’s group number) using “Do a Search for Support Emails” (constraint: Group Number = Current User’s Group Number").

Note: for the 6th support person, their Group Number could still be ‘6’, but the constraint will be “Group Number = 0”, since every 6th Support Email has a Group Number of 0 (since every 6th item for <-modulo->6 equals 0).

I hope I didn’t make this super confusing - if you have any questions or need help setting this up in your app feel free to let me know! :slight_smile:


@ahaller and @fayewatson - thank you for your answers, super helpful. @fayewatson - great level of detail, thanks, it does make sense! I think I can get something working in my app now.

1 Like