So I now have a bunch of services in my prototype application and I am using self.invoke() on a number of tier 2 services. All those invoked, tier 1 services access the PostgreSQL database like this (very much simplified version):
with closing(self.outgoing.sql.get(conn).session()) as session: result = session.Query() # Whatever query if result: # Some code self.response.status_code = OK self.response.payload = result
So now my tier 2 services both access some information on their own and invoke other tier 1 services. In some cases they just invoke other services and do not access the database on their own. Anyway, the thing is that the block above which (if I am not mistaken):
- Reuses a connection from the pool.
- Starts a transaction (in general, there exists services for CRUD operations).
- Commits or roll backs the transaction, if applicable.
- Closes the connection (i.e. returns the connection to the pool).
So I was wondering which is the internal behaviour in Zato when you invoke another services which also uses a connection to the database. Is it reused? Is the session (transaction) reused? If not, does it start another transaction on its own?
I am asking all these questions because I am now creating the service that creates a new reservation, which invokes services to:
- Get a list of extras.
- Insert or update a guest.
- Insert a booking.
- Get information of a room.
And each of these tier 1 services have a connection block such as the one described at the beginning of this post.
P.S. Just incidentally, PostgreSQL features savepoints, which are kind of partial commits of transactions.