Discussion Forum

How to deal with session and client when building api

I’m trying to build backend api of grakn 1.8.4 for a frontend UI. During the coding, I found different behaviors for putting session and client inside or outside of sub function.

Assue, in a script, if all functions share the same session, but not clients, then sometimes, the results are not updated in grakn. And sometimes, I found the inconsistence between console and coding output.Sorry, I couldn’t explain the question more specifically. But I think I’m lacking of some key understandings.

What’s the best practice to deal with session and client when coding the backend api?

It’s possible there are some descrepancies in 1.8.4 - we didn’t provide any hard guarantees on Isolation and Consistency then. You should generally be able to pass a session around though, as long as you open new transactions after a commit to make sure you can see the newly committed changes.

The idea of a session is that it corresponds with one group of actions. So if a user uses a chatbot or logs into a website, one user interaction “flow” can be a session, and each set of tasks within that flow is intended to be a transaction.