When the Current system needs to send email notifications it waits until all emails deliver then send’s the response to the front-end, the problem is it takes at least 5 seconds to send an email to one email account and get a response if there are 500 accounts to send it will take at least 41 minutes to get a response from the server.
These are the possible alternatives I found to overcome the above problem.
- Sendgrid or another email service that provides an API (instead of SMTP)
Using an email service like Sendgrid will reduce this problem and improve server performance because it uses API calls instead of SMTP. However, there is a daily threshold in most of the services (in free versions). It’s 500 per day in Send grid. There’s a possibility that we might exceed that limit because ScholarX sends bulk emails when there’s a state change. Therefore, it might not a good solution to address the problem.
If we use multi-threading it will improve the response speed of the same implementation. I’ve implemented a thread into a single state as a proof of concept. Here are the results,
The current response speed of the current implementation,
If we use Threads,
I tested these with three accounts registered as mentors for both scenarios, it took around 17.87 seconds to get a response from the server, after I added a separate thread to send emails, it only took 40.1ms to get repones from the server, according to these results, if we use multithreading in the current implementation, it will improve the response speed of the current implementation by 97.6471%.