Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Wouldn't it be better to do the calc in your app and save it to the db? Best of both worlds


Yes, but increasingly for us we tend to have several "apps" accessing our data: The mobile, desktop and API 'apps' are all different code bases for us.


So long as everyone, everywhere, always remembers to calculate it in the same way for all inserts and updates.

This seems a lot more robust to me.


You can use abstractions that push such code out of the developers concern, into the "code infrastructure" layer.

But there are also plenty times where I'd rather compute at the database side; there are no silver bullets.


And then someone at support comes along and updates the data via SQL and forgets to update the derivative field because he got woken up at 2am for an emergency.

Using a computed column ensures the data is consistent.


And if another consumer of the DB doesn't do the calculation or, even worse, does the wrong calculation?


what if you have 50 apps talking to the same DB?




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: