Functions vs Jobs & Queues

If you've already read about jobs and queues you might ask yourself "when should I use functions and when should I use jobs and queues?".

There's a lot of similarities between them and both can often be used for the same use case. You can think of functions as a lightweight version of jobs & queues that are well suited for use cases where creating a job and a queue feels like overkill.

A key difference is that functions can only be created by .NET code and you can't have an external system adding a function call through the API like you can with queues.

Another big difference is that queues allows you to separate concerns in a better way. The part of the application that creates a queue message has no idea what will happen when that message is processed, but when you use a Nexus function the caller has to specify what service should get called. There's also no way of doing batching with functions like you can with queue jobs. That is, if 100 calls to the same method gets scheduled there's no way of grouping them into a single call to the service.

A rule of thumb is to start with a Nexus function if that works for your use case, and later on move it to a queue job if you need to.

Tip: Use only functions

The functions, jobs and queues sub systems are independant from each other and can be used in isolation. So if you don't have any need for jobs & queues you can skip registering those sub systems and only call builder.Services.AddNexus().AddFunctions().