https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
d

damp-toothbrush-94983

06/30/2023, 3:10 PM
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

fresh-football-47124

06/30/2023, 3:11 PM
Hi Michael. What do you mean by “status”?
d

damp-toothbrush-94983

06/30/2023, 3:17 PM
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

fresh-football-47124

06/30/2023, 3:20 PM
what is the tech stack?
d

damp-toothbrush-94983

06/30/2023, 3:23 PM
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

fresh-football-47124

06/30/2023, 3:24 PM
for JS, we do have real time updates with SSE
which you can enable
d

damp-toothbrush-94983

06/30/2023, 3:25 PM
during create GrowthBook object?
f

fresh-football-47124

06/30/2023, 3:28 PM
you have a single page app?
d

damp-toothbrush-94983

06/30/2023, 3:30 PM
no
f

fresh-football-47124

06/30/2023, 3:30 PM
are you using GrowthBook client side or server side? (or both)
d

damp-toothbrush-94983

06/30/2023, 3:34 PM
both, ui is react and backend is java
f

fresh-football-47124

06/30/2023, 3:46 PM
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

damp-toothbrush-94983

06/30/2023, 3:49 PM
ok, thanks!
b

better-magician-65629

07/04/2023, 5:02 PM
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

damp-toothbrush-94983

07/06/2023, 12:19 PM
Got it. Thanks
@better-magician-65629 dose reat have similar function?
b

better-magician-65629

07/06/2023, 6:03 PM
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

damp-toothbrush-94983

07/14/2023, 3:13 PM
@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

better-magician-65629

07/14/2023, 4:46 PM
creating a new GrowthBook instance for each request is recommended, and the GBFeaturesRepository (if you're using that) should be a singleton
d

damp-toothbrush-94983

07/14/2023, 5:31 PM
thanks
b

better-magician-65629

07/14/2023, 6:39 PM
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.
7 Views