Session duration / best practices

What are best practices around session reuse?
what is the cost/overhead of creating a new session for each transaction? should I do this?
this is for multiple sequential TXs.

I've been keeping a session for a long duration, but I started getting a SessionExpired error.

Should I track the duration myself? Or just create new sessions all the time?
Or is there a simple way to test if the session is valid (without a roundtrip)?

   ❌ ERROR: NEO ERROR {
  "error": {
    "code": "SessionExpired",
    "name": "Neo4jError",
    "retriable": true
  },

Sessions are lightweight to create and are supposed to be created each time you need one. They are not thread safe either.

If you use transaction functions you get retry logic and you can chain together queries and java logic within one transaction.

You could use the same session if you want to process queries in separate sequential transactions within the same thread.