Maintaining transaction offsets across service re-runs
I use the TransactionsClient from the ledger API to listen to newly created transactions, and I specify a LedgerOffset begin value to identify the offset from which to start listening to transactions.
As I create and process transactions, I do maintain the latest TX offset value, but I do not persist it (yet). I need to persist the offset so that the next time I restart my service, I pick up where I left.
Are there any DAML-esque ways of persisting this offset value?
Can you clarify for me what you mean by “Daml-esque”? In general, the offset can be persisted in any way it suits your specific application, including “just” writing it to a file. If your application is backed by a transactional data store (like a relational database), piggy-backing on your store’s transactionality to process the events and storing the offset as part of a single transaction is probably a very nice property you want to use. Otherwise you’ll need to consider what happens if you only processed parts of a transaction as a failure happens and take steps to deal with that (processing events in an idempotent fashion might help, as well as keeping track of the event ID within a transaction, but the details depend heavily on your application’s logic and the transactional properties of your application’s secondary data store).
In addition to the standard persistence stores (files, dbs, etc) that you mentioned, I just wanted to know (since I’m fairly new to this) if there were other well-defined patterns. All clear. Thank you Stefano.