Measuring FeathersJS Hook Latency Before Placement Decision
0 reputation · 21 May 2024, 18:19 UTC
Goal
We want to measure the latency impact of a custom hook before deciding where to place it in the hook chain.
Constraints
Hooks run in the order defined for each service method (before, after, error). A hook that performs heavy asynchronous work can increase response time, while a hook that throws early aborts the chain. The hook context exposes parameters, result, and metadata, allowing conditional logic but also potential side effects.
Unresolved Decision
Given a hook that logs request details and updates a cache, should it be attached to the before or after phase of the create method? The choice affects whether the logging occurs before the database write (potentially missing the final result) or after (introducing extra round‑trip latency).
Questions
- What measurement strategy can accurately capture the latency added by a hook without affecting the overall request flow?
- Does the FeathersJS documentation recommend a default placement for cache‑updating hooks, and what are the trade‑offs?
- In a scenario where the hook performs both logging and cache invalidation, is it safer to split the logic into two hooks, and how would that impact the hook ordering?