When to flush write buffer? (api server)

I recently discovered InfluxDB and it looks quite cool :wink:

As part of a PoC I’d like to use it to collect some measures of a REST API written in GO usingthe Gin Framework. Everything works well so far. To go a little bit further, I’d like to refactor from blocking to non-blocking WriteAPI.

In my REST API Server, I open one central connection to InfluxDB in my main() and inject the write/read API into my models. Close is called using the defer keyword.

I wonder when is the right/best time to call the writeAPI.flush() method, to make sure writing remains async.

Should I do that in the models (their functions are called by the handlers) when I’m done writing the points, or should I even launch a GO routine which calls it every minute or whatever? By “handlers” a mean the function that’s executed for GET calls to the server, so these are many, small calls.

Hello @omsec,
Welcome!
I’m not entirely sure. Can you please share your code?
Have you seen GitHub - influxdata/influxdb-client-go: InfluxDB 2 Go Client
Thank you