Skip to main content

Double trouble

This event driven architecture Writestreak is largely build is great. I'm loving it more and more every day. But despite my vast experience in web technologies and architecture it's different enough to also cause some unexpected headaches.

Since the beginning of the week you might have noticed double notifications whenever there is a mention or comment for your posts. It's not you seeing double, those notification events just ended up triggering twice.

You see, I'm not doing the notification triggers when a new post or comment is saved. Well, at least not in the same call as is the traditional way. Neither do I check periodically if there are new posts or comments that should trigger a notification. With events I can just trigger another function that will handle the notifications whenever there is a new item saved into the database. Trust me, this makes things simpler, by a lot!

... That is - as long as you remember you are using such an architecture. In traditional model you can change the code saving posts for example as you see fit. You can even rename the calls and so on. As long as you don't introduce any bugs while doing so everything gets updates upon next deployment. With evented functions it doesn't go like that.

Let's say you have the original function deployed into production, lets say notifyOnNewPost which triggers whenever an entry is saved under posts -table. Later, you decide to restructure your functions in logical collections. You move all the notification function under the group notify so the previous function becomes something like notify.newPost. The function, while having a new name is still triggered on same events and does the exact same thing. But unless you remove the old function from the running deployment it too will trigger and do the same!

That was the oversight I missed when deploying the latest restructure of the code. I actually knew the old functions would be left running. The deployment tool is intelligent enough to notice these kind of changes and it did offer me the option to delete all those old functions. Not thinking they could cause such trouble I decided to keep them running, just in case. After realising thus I have now removed those old functions and there shouldn't be any more double events.