Menu

Expand
Rate this page:

Queue Ordering

LIFO vs. FIFO

A TaskQueue's default ordering is FIFO - First In, First Out. This is best used for most scenarios common within a Contact Center, such as handling incoming voice calls, emails, etc.

LIFO - Last In, First Out - is the alternative ordering option for TaskQueues; it is useful where routing most recent tasks first is required. Unlike FIFO ordering, LIFO ordering does not consider the Task priority when ordering Tasks.

For example, a real estate company may generate leads on their website and have agents call back those leads. A lead is hottest at the moment it's created, and 'cools down' quickly, equating to an increasingly lower chance to convert that lead. It is therefore highly desirable to connect the first free agent to the hottest (newest) lead in the system, since that has the highest likelihood of conversion. To do this you should use the LIFO routing setting, rather than using ever-increasing priorities on top of a FIFO queue.

LIFO is a TaskQueue level setting, enabled by passing `TaskOrder=LIFO` while creating a TaskQueue or updating an existing TaskQueue. If no `TaskOrder` is passed, the setting defaults to FIFO. If your Workspace has Workers shared between LIFO and FIFO TaskQueues, then you can use a workspace level setting `PrioritizeQueueOrder` to decide whether to prioritize LIFO or FIFO. Simply pass `PrioritizeQueueOrder=LIFO` or `PrioritizeQueueOrder=FIFO` while creating a new workspace or updating an existing workspace.

Let's imagine the Tasks from the following FIFO and LIFO TaskQueues are routed to same group of agents, then let's examine how the PrioritizeQueueOrder setting works. We'll represent tasks as the task furthest on the right is the next to be assigned to the agent.

In a FIFO Queue, if you have 5 tasks from F1 as the oldest to F5 as the newest, they will be routed:

Inbound Tasks -> F5, F4, F3, F2, F1 -> Agent

In a LIFO Queue, if you have 5 tasks from L1 as the oldest to L5 as the newest, they will be routed:

Inbound Tasks -> L1, L2, L3, L4, L5 -> Agent

If your Agent is part of both TaskQueues, then the preference by which they consume tasks from a FIFO Queue vs a LIFO Queue depends on the PrioritizeQueueOrder setting. For example, if we combine the two examples above, and set PrioritizeQueueOrder to FIFO then the Tasks are routed in the following order,

Inbound Tasks -> L1, L2, L3, L4, L5, F5, F4, F3, F2, F1 -> Agent

Compared to if PrioritizeQueueOrder is set to to LIFO

Inbound Tasks -> F5, F4, F3, F2, F1, L1, L2, L3, L4, L5 -> Agent

There are many possible use cases that can be satisfied using LIFO, or combining LIFO and FIFO Queues. If you find you need additional functionality on top of LIFO and FIFO, we want to hear from you. Please contact support and tell us about it.

Queue ordering vs agent ordering

Please note that queue ordering is about ordering of tasks waiting within a given queue. That ordering can be FIFO or LIFO. FIFO task queues are additionally sorted by task.priority.

Once a task gets to the front of a queue, then the ordering of which worker is selected to handle the task is a separate concept - the order_by expression.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...
        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        thanks-feedback-gif