When i started as web-developer i used to write almost all the code in my controllers in java or in views if its python but later realized that they not only reduce the performance or speed but also there is no need to have them in controller.
If you dont get it let me explain, Think of implimenting sending an email after an user registered to your website. The normal way is to call your smtp send mail function from controller right after successful registration and after the smtp execution is complete user is redirected to some page. This is called executing somthing synchronously.
But there is better way implement the problem which is asynchronous and it wont wait till smtp completes execution.
Yes the asynchronous background tasks can be created to do the time consuming non Request dependent tasks. in our case its mailing, We can use an background task execution for sending email and register the task when user is registered.
The advantages of using asynchronous tasks much more than that. Think of sending a mail daily morning like a news letter or validating all validity based functionalities.
The scheduled jobs like crons can be implemented in modren web applications using plugins like celery in python and spring batches in java.
There are many other techniques to implement some of the easy ones are
- Django background tasks
java.util.concurrent.CompletableFuturefrom java 8 onwards
542 total views, 1 views today