Skip to content

SDK Review #1

@toddbaert

Description

@toddbaert

I've opened this issue as a place to centralize review of the Swift SDK built by Spotify. Thanks to all that have worked on this. The community is excited to have this contribution!

I've gone through the code as best I can (as a Swift novice) and here are my observations so far:

Spec compliance

These are the things that seem to not yet be implemented from a specification perspective. We may not need to implement all of them for a 1.0, but they're worth pointing out!

FlagMetadata

Multiple provider support

  • This is not implemented, see here, here. There's some additional background here.

Provider initialization/shutdown

  • This is partially implemented.
    • The provider interface needs a "shutdown" function to clean up timers, threads, connections, etc. See here, and here
    • The API needs a shutdown function to shut down all providers gracefully when the application terminates, see here.
    • This gets a bit more complex with multiple providers

Named provider (aka multi-provider) support

  • This is not implemented, see here, here. There's some additional background here.

Events

  • This is not implemented, see here.

General recommendations and observations

These are things that aren't really about spec compliance, but general points I've noticed:

The Features protocol is synchronous

  • This is what I would expect, just as it is in our client JS implementation: https://github.com/open-feature/js-sdk/blob/main/packages/client/src/evaluation/evaluation.ts. I'm only pointing it out because it's an important choice that should be noted and considered. I think it makes sense for client situations ("static" contexts), wherein we expect values to be fetched during initialization and updated during context changes, and then cached. I just want to make sure that providers will likely be able to fulfill this contract. Is it likely that providers won't need to do any async work (besides when they initialize and react to context changes?). If so, I think this implementation is good.

Value

  • Similarly to Kotlin, I'm wondering if there's a "simpler" alternative for representing arbitrary structured data in a type-safe, serializable way here. For example, in TS/JS this is just a plain object with the type restrictions. In Go it's a map[string][interface{}]. I would recommend whatever the "standard" way of representing a JSON object is in Swift, if one exists.

Metadata

  • I recommend calling this ProviderMetadata or something else. We regretted this naming in other SDKs, since we found number use-cases for a generic Metadata object that carries arbitrary information (FlagMetadata, and EventMetadata, for instance).

setProvider is an async function

  • This is similar to the discussion in the Kotlin SDK (suspend). In JS we made the intentional choice to make this method non-async. The initialize() method is being called in here, but it's not awaited. When the init completes, READY/ERROR is emitted based on if the method was successful or not (see here).
  • I'm OK with making this an async function in theory, but I think it's a bit inconsistent with the events API, and our other SDKs. Another thing to consider is that client instances (which may be in a completely different place in the codebase) can't await (or react to errors thrown by) the async setProvider; events are needed for this, which may make it less sensible to mark this async.

Proposal

Like the Kotlin SDK, this looks very good to me. I see most of these issues as non-blocking, and good for initial release. I would just consider how to prevent breaking changes as much as possible. Specifically, consider the points above about Value, the async setProvider, and the synchronous Features protocol.

It would also be very helpful to use the template readme here, for a 1:1 comparison between other SDKs.

I would love to hear input from the contributors from Spotify and the OpenFeature community in general on my proposal above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions