2.4.1.5 Performance & Indexing

1. Indexes

• Index frequently queried columns: e.g., userId in Posts or Trades, createdAt for sorting.

• Composite indexes for queries that filter by multiple fields (e.g., userId + createdAt).

2. Query Optimization

• Avoid N+1 queries by eager loading associations in Sequelize (include arrays).

• Use raw queries or stored procedures for performance-critical operations.

3. Partitioning (Advanced)

• For large tables (e.g., ChatMessages), partition by time or by channel ID if volume is extremely high.

4. Replication

• On AWS RDS, add read replicas to offload read-heavy queries, especially for analytics dashboards.

Last updated