3 ms·
I'm using the same definition. Writing data to a database is a side effect. If there is no side effect then what's the point of calling a service? So it does co
by friendly_chap 9y ago
I'm using the same definition. Writing data to a database is a side effect. If there is no side effect then what's the point of calling a service? So it does computation? Then who saves the result of that computation, thus doing a side effecting operation?
If no one then what's the point of that service's existence?
- dvt 9y agoA side effect is by definition some mutation that's out of the scope of the function -- if the purpose of the microservice is to put stuff in a database, then (by definition) it's not a side effect. Switching a flag on top of doing some work, on the other hand (e.g. flip "processed" to true in a global database) is a side effect.
- brucephillips 9y agoIf a function writes to a DB, yes, that's a side effect. I think you're conflating "scope" and "purpose".
- dvt 9y agoCorrect, my bad.
- friendly_chap 9y agoModifying data in a database is a side effect. Since you brought up the wikipedia definition, here it is: > In computer science, a function or expression is said to have a side effect if it modifies some state outside its scope or has an observable interaction with its calling functions or the outside world besides returning a value. For example, a particular function might modify a global variable or static variable, modify one of its arguments, raise an exception, write data to a display or file, read data, or call other side-effecting functions. Note "write data to a display or file". I think we agree that writing to a database falls under this definition, hence using terms like "side effecting" when talking about microservices is misleading.
- dvt 9y agoYeah, I stand corrected. I am indeed conflating scope with purpose. Should've been clearer in my OP.
- Retric 9y agoTechnically it depends on if anything outside the service can see the database and if the state is saved after the service returns. It might seem useless to call a DB if you're not going to save state, but a Rube Goldberg architecture could do so for the lulz.