Hello I am new with Growthbook. I wonder if GB SD...
# ask-questions
d
Hello I am new with Growthbook. I wonder if GB SDK would keep to update the features status in my application, or my application needs to implement it?
f
Hi Michael. What do you mean by “status”?
d
Maybe refresh is better. I mean how our application get latest features' value, on/off
Does SDK have such function or GB service will send stream and let SDK keep the sync with GB server?
f
what is the tech stack?
d
in our app, we will call growthbook.loadFeatures() in App.js to get all features. I wonder how our app gets the latest status of these features?
f
for JS, we do have real time updates with SSE
which you can enable
d
during create GrowthBook object?
f
you have a single page app?
d
no
f
are you using GrowthBook client side or server side? (or both)
d
both, ui is react and backend is java
f
okay, both those SDK languages support streaming updates
which will update realtime
you can DM me your SDK id and I can enable it for those endpoints if you want to test it out
d
ok, thanks!
b
java supports refreshing the features with a stale-while-revalidate approach. you can read more about that here, but essentially:
When you fetch features and they are considered stale, the stale features are returned from the
getFeaturesJson()
method and a network call to refresh the features is enqueued asynchronously. When that request succeeds, the features are updated with the newest features, and the next call to
getFeaturesJson()
will return the refreshed features.
d
Got it. Thanks
@better-magician-65629 dose reat have similar function?
b
yes the react SDK uses the JS SDK. you can read the docs on auto-refreshing here for more info: https://docs.growthbook.io/lib/js#loading-features
d
@better-magician-65629 and @fresh-football-47124 In java code, I should create GB object each time to get refreshed feature value?
in the above code example, each end point controller creates gb object with each call
b
creating a new GrowthBook instance for each request is recommended, and the GBFeaturesRepository (if you're using that) should be a singleton
d
thanks
b
i've also added another example that may help DRY up the request using a HandlerInterceptor, so you don't need to create it inline with every request. https://github.com/growthbook/examples/tree/main/jvm-spring-web#handlerinterceptor-implementation
also you asked about "refreshed feature value" – refreshing of features is handled in the GBFeaturesRepository. you can learn about the refreshing behaviour here: https://docs.growthbook.io/lib/java#fetching-cacheing-and-refreshing-features-with-gbfeaturesrepository a new GrowthBook instance is recommended for each request so that there aren't race conditions between requests calling setAttributes and evaluating features on a single instance.