I've been developing a SAAS (Software as a Service) application recently in which doctors can onboard their patients onto our platform. Our platform has a feature that allows it to be integrated with other frequently used software solutions. In this functionality, doctor can choose a third-party tool (in this case: Google Sheets) and can export the platform data. Here's where there's a problem that platform is taking too long to export the data, which becomes a major issue for Doctors. Consequently, a user story is produced and given to me. See how I approached this.
Problem
response is way too slow when we clicked on export button to transfer data to Google Sheets, which is a serious issue for doctors. Below is a diagram of the visual flow. Therefore, when the doctor clicks the export button, it stucks there.
Below GIF shows the slow response when Exorting the Data
so below GIF shows that when doctor clicks on the button to export the data, it is just showing Exporting... for long time.
Brainstorm
How and what data do I gather?
- I start by opening the form's frontend, where doctor's are exporting the data.
- I looked at the network tab and noticed that the backend Rest api's average response time was longer than usual.
- Let's have a look at the Rest api's design and sequence diagram, which we are using to export the data to google sheet.
Export Data API's UML sequence diagram is shown below
Let's extract a flaw in this design
- currently there is only one API which is responsible for 2 tasks:
- creating the sheet id in google sheet
- second is pushing the patient's data from our platform to google sheet.
- so the problem is our api design is not following the single resposibility principle which says one function/api should perform only single action
- due to this our API response time is high as well code is not much maintainable
- second is our frontend is also performing 2 tasks in single click.
Solution
Let's see what we need to do in order to solve this issue
-
first on backend side we have to break down our API into 2 seprate API's:
- so first API is only responsible for creating a google sheet and return the sheet id
- second API is only responsible to push data of patient's record to given sheet_id
-
second we have to change our frontend part
- so instead of only one button we first create a button to create the sheet id
- second button is responsible for sync/exporting the data
Below is the final Sequence Diagram
Below is the final/new frontend for Exporting data
you can read about Single Responsibility principle here → single responsibility principle