Persistence

I want to ask what is the approach for persistence for a daml ledger client, do i store the template-contract id pair for each each to query active contract and thus the data, or do i do ATS with the value gotten from StateService GetLedgerEnd, i am lost on what to hold reference to and store to query the ledger for data regarding my users, as i can’t use contract keys as i am on 3.3

Hi, David.

You are on the right track. You can query for contracts in the Active Contact Set, filtering by the contract template and/or parties. The response gives you both the contract id and the payload. For small apps, that may be sufficient. Obviously, that approach would not scale well.

For scalability, you may need to subscribe to updates on the ledger and write that data to a relational or document database. Your database would store the contract id and the payload. Your database would be a “projection” of the source data (which is on ledger).

This idea of keeping an indexed, searchable copy of the data is referred to in the docs as an Operational Data Store (ODS).

Digital Asset provides one such ODS named the Participant Query Store:

PQS provides a general-purpose, queryable view of ledger history and state suitable for a wide range of use cases. PQS is the recommended path for automation and integration components to access ledger data.

Also see A Docker Compose demo of the Participant Query Store (PQS)

i guess PQS only works for canton ledger deployed and not the local ones?

I guess i would stick with the other approach and look into PQS as we scale.

The PQS can be used for any ledger, including Sandbox, a local Docker Compose network, etc.

That’s a reasonable starting point, if you don’t need it and want to avoid adding one more component to the system.