MATH Best Practices

Hi Guys!

I am building an app that lets my users perform an audit. The audit then gives them some scores/percentages etc.

Here’s a screenshot of the design file to give you an idea:

My Question: Is it best to write the scores to my DB or to just render them live on the page?

I have observed that writing it to the DB is very slow compared to rendering it live.

For example the “Total Score” when written to the DB takes about 2 seconds to render correctly if I do the math on a backend workflow and write it to the DB.

On the other hand, if I set the text field for Total score to just be a math expression that calculates it, then it’s instantaneous.

As I see it - the big reason for writing to the DB is that if I just render it on the page this could create a lot of workload units as I have to search for lists of things almost constantly. However, like I said, very slow.

I don’t really have any other reason to write the scores to the DB - anytime I need the total score I can just do the math at the moment I need it, rather than looking it up.

Rending the score as needed also means I don’t have to have workflows for keeping the score updated if it changes.

Thanks for you input!

Personally I’d write to the database. Especially with new usage based pricing model. More because let’s say you have users who refresh the page, that will require you to re run all equations.

Database will also allow you to quickly show the user their results on future viewings.

Your decision on audit tools like this should also be based around your 3rd party dependencies and how they work together. Personally I’ve done a digital audit for websites & businesses.

This required us to use SEO APIs, Google lighthouse, keyword APIs, and more. The return of everything took 30 sec + usually. Some data was needed from a prior api to execute the next so saving to the DB worked best but also kept costs down & improve our users waiting experience with UI.

1 Like