limited-ram-77544
08/23/2023, 3:20 PMCreate a separate GrowthBook instance for every incoming request. This is easiest if you use a middleware:May I know why a separate instance needs to be instantiated for each request? Wouldn't this create many instances proportional to the traffic the server is handling? Is it possible to have a cached GrowthBook instance across the server and we just add it to the
req
property and override the attributes if required like req.growthbook.setAttributes({...})
for incoming requests?happy-autumn-40938
08/23/2023, 4:24 PMlimited-ram-77544
08/23/2023, 4:46 PMgrowthbook
property within the Express req
object at a middleware level
Let's say you have a downstream service (e.g. serviceC) depending on a feature flag.
E.g. middleware -> controller -> serviceA -> serviceB -> serviceC
Does this mean that I need the pass the growthbook
object from req from the controller level all the way down to serviceC? This seems similar to "prop-drilling"
Is there a way serviceC can just obtain the singleton from the SDK?
I considered just initialising a new SDK instance in serviceC and reading the value of the flag. This would work for normal usage but not for percentage-based rollouts which would depend on the attributes set by the middleware layer (e.g. an authorization middleware that sets user-specific attributes like email and role).
Is there any recommended approach here?happy-autumn-40938
08/28/2023, 5:21 PMctx
object and passing that between services.limited-ram-77544
08/29/2023, 2:11 AMctx
as you suggested. Thanks for the input @happy-autumn-40938!