launchdarkly/java-server-sdk

Combine File data source and Streaming data source

asaha123 opened this issue · 2 comments

Is your feature request related to a problem? Please describe.

We are discussing a situation where the Java SDK - when it is starting up as part of an application is unable to communicate with launch darkly - perhaps a networking issue or an invalid SDK key. In this scenario, feature flag evaluations will use the default values - an undesirable situation for us.

Describe the solution you'd like

In the above situation, we would want it to startup initially bootstrapped from a file (i.e. the file data source) and then attempt to switch to the streaming behaviour. I have been taking a look at the code and i was wondering if the current code would allow me to somehow inject the datastore that was created when using the file data source when using the streaming data source. So something like (in pseudo-ish code):

# First read from files
    LDConfig config = new LDConfig.Builder()
            .dataSource(
                    FileData.dataSource()
                            .filePaths("file1.json", "file2.json")
                            .autoUpdate(true)
            )
            .events(Components.noEvents())
            .build();
    
    LDClient client = new LDClient("sdk key", config);

# Then, switch to the streaming data source with
config.DataSource = < existing data source above>
LDClient client = new LDClient("sdk key", config);

So, instead of overwriting the data in the second step, it performs only upsert operations.

Describe alternatives you've considered

We understand ld-relay can help us here, but we are considering the alternatives due to some specific concerns - unrelated to ld-relay itself.

Additional context
NA

The current architecture doesn't allow switching horses in midstream like that. Something similar has been suggested in the past (either for this SDK or another one, I'm not sure) and we've considered it, but hadn't moved forward due to 1. a lack of demand and 2. some design questions that made it not quite as straightforward as you might think— the suggestion at that time was that both data sources would be in effect from the start, so that the file one could be used to provide flags that weren't coming from LD, but that raised questions of how to determine which one took priority.

In any case, with the current SDK the only workarounds I can think of to accomplish something like this would be fairly elaborate and probably brittle.

Thanks for sharing your thoughts.

the suggestion at that time was that both data sources would be in effect from the start, so that the file one could be used to provide flags that weren't coming from LD, but that raised questions of how to determine which one took priority.

My 2-cents on this would be something very naive where we could setup up a hierarchy of data sources where the one later in the hierarchy overrides the one before with the logic that only of them being available is considered enough for the datastore to have been initialised.