Before we starting our discussion to set up a background job we first need to understand Why We Need Background Jobs & Queueing?
If you are a developer, you always concern to build a scalable system. But you never expect that any External Dependency (3rd Party APIs) & CPU Intensive work could affect your systems' latency. In order to maintain your systems' latency, you can take advantage of background jobs.
Here is some list of use cases where one can use background jobs.
Generating reports using database aggregation.
Generating thumbnail of images OR videos.
Filtering message contents and censoring data of chat applications.
Any service which performs CPU Intensive OR Dependent on external services, Taking more than 1 seconds.
Anatomy of a background job:
Job: A task which needs to be done.
Worker: Is labour who does the job.
Queue: Is a manager who manage the workers & jobs. Assign the right job to the right worker.
Tools which we use for building Background Job:
If you want to know more about firebase you can learn it from here.
Let's start creating a project on firebase:
Let's generate a private key to access this project programmatically:
Till now we have done preparatory steps. Now let's get into the code.
Before we build a solution lets first discuss a problem statement and then try to design a solution using the background tasks.
Consider we are into logistics business, We always want to track the on-field vehicles, also want to create a fence on a location so that if a vehicle reached the fence we would get a notification.
Our all vehicles have a GPS device installed, which periodically sending the location status of the vehicle.
We will discuss the solution in my next part-2 blog.
Until you may present your thoughts, feedbacks & criticism on comments sections.