Jovo Middlewares and DB operations


About Jovo middlewares and Jovo hooks :
I am wondering why is the middleware before the response one ?
Wouldn’t it be better for performance to have DB operations be postponed after the response is sent ?
Do you think it’s possible to use AWS Lambda and an after.response hook to do all custom DB operations or the Lambda would have to wait for all operations to be done before sending back the response ?


Hi @Quentin, welcome to the Jovo Community Forum! :tada:

This is an interesting idea. I think @AlexSwe is the best person to answer this, but it’s definitely an interesting thing to think about. One more idea we had was to add an additional middleware after the response for cleanup operations. And you’re right, maybe we’ll move the DB stuff there in future versions if it makes sense.

Yes, you could do custom operations after after.response, the JSON response would already be sent out, but the Lambda would stay open as long as all the asynchronous operations are done.


Yeah. This is what internal my API does actually.

And one more step - Doing a ‘diff check’ can save you writing the data if nothing has changed.
If you are not ‘counting individual interactions across sessions’ it’s pretty common for the user data to not change in a turn, so why write it! (Maybe you’ve optimised this already - I think we discussed it some time ago Jan)

Hooray for the forums BTW!


Welcome to the Jovo Community Forum, @PeterNann :tada:

Ah yes. Indeed, currently there is not a lot of optimization done here. This is definitely something that could use some work! I know that @Kaan_Kilic is currently working on a DB integration refactoring, maybe this is worth a try, Kaan?


Sure, I will have a look :slight_smile:


Hi @PeterNann, here is the Pull Request by @Kaan_Kilic if you’re interested in taking a look: