Process data in batches
Make sure that you use batch processing throughout your code: transform data in memory over the whole batch and persist it with a small number of batchedupsert/insert calls. Avoid loading or saving single entities unless strictly necessary. Consider using @belopash/typeorm-store for large projects with extensive entity relations and frequent database reads.
Select only the fields you need
Data requests are configured at the processor level. UsesetFields to request only the fields your handler actually reads — see field selection. Requesting fewer fields means smaller responses from the data source and faster syncing. The same discipline applies to data requests themselves: subscribe only to the addresses, topics or calls you process.
Filter data in the batch handler
Even when your processor configuration requests data from particular contracts or addresses, check in the batch handler that each data item matches what your processing code expects (e.g. that theaddress field of a log matches the contract address before decoding it). This ensures that future changes to the processor configuration will not silently route newly added data to your old processing code.
Index your database
If your squid saves its data to a database, make sure your schema has@index decorators for all entities that will be looked up frequently.
- Follow the queries optimization procedure for best results.
- If your squid repeatedly rewrites the same rows (per-block prices, TVL, balances, positions, etc.), tune those update-heavy tables so the updates stay cheap and the tables don’t bloat over time.
Harden your GraphQL API
If your squid serves a GraphQL API:- Do not use OpenReader if your application uses subscriptions. Instead, use PostGraphile or Hasura.
- If you do use OpenReader, configure the built-in DoS protection against heavy queries and set up caching.
- If you use PostGraphile or Hasura, follow their docs to harden your service in a similar way.
Prepare for production deployment
If you deploy to SQD Cloud, go through the Cloud best practices checklist: a professional organization, dedicated resources, an adequatescale: section, zero-downtime updates, secrets for all sensitive data and proper logging.