Skip to content

Commit a5a2ba3

Browse files
authored
feat: add isolated instance (#368)
Adds spec for isolated instances. Resolves: #359 Relevant work: - open-feature/js-sdk#1325 - open-feature/js-sdk#1342 --------- Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
1 parent eefdf43 commit a5a2ba3

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

specification.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,34 @@
365365
"RFC 2119 keyword": "MUST",
366366
"children": []
367367
},
368+
{
369+
"id": "Requirement 1.8.1",
370+
"machine_id": "requirement_1_8_1",
371+
"content": "The `API` MUST expose a factory function which creates and returns a new, independent instance of the `API`.",
372+
"RFC 2119 keyword": "MUST",
373+
"children": []
374+
},
375+
{
376+
"id": "Requirement 1.8.2",
377+
"machine_id": "requirement_1_8_2",
378+
"content": "Instances returned by the factory function MUST conform to the same `API` contract as the global singleton, including flag evaluation, provider management, context, hooks, events, and shutdown functionality.",
379+
"RFC 2119 keyword": "MUST",
380+
"children": []
381+
},
382+
{
383+
"id": "Requirement 1.8.3",
384+
"machine_id": "requirement_1_8_3",
385+
"content": "The factory function for creating isolated instances SHOULD be housed in a distinct module, import path, package, or namespace from the global singleton `API`.",
386+
"RFC 2119 keyword": "SHOULD",
387+
"children": []
388+
},
389+
{
390+
"id": "Requirement 1.8.4",
391+
"machine_id": "requirement_1_8_4",
392+
"content": "A `provider` instance SHOULD NOT be registered with more than one `API` instance simultaneously.",
393+
"RFC 2119 keyword": "SHOULD NOT",
394+
"children": []
395+
},
368396
{
369397
"id": "Requirement 2.1.1",
370398
"machine_id": "requirement_2_1_1",

specification/glossary.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This document defines some terms that are used across this specification.
3131
- [Provider](#provider)
3232
- [Provider Lifecycle](#provider-lifecycle)
3333
- [Domain](#domain)
34+
- [Isolated API Instance](#isolated-api-instance)
3435
- [Integration](#integration)
3536
- [Evaluation Context](#evaluation-context)
3637
- [Transaction Context Propagator](#transaction-context-propagator)
@@ -125,6 +126,10 @@ The possible states and transitions of a provider over the course of its usage,
125126

126127
An identifier which logically binds clients with providers, allowing for multiple providers to be used simultaneously within a single application. Domain binding is dynamic; it may change over the course of an application's lifetime (i.e.: a client associated with the default provider via an unbound domain will be bound to a new provider if a provider is subsequently assigned to that domain).
127128

129+
### Isolated API Instance
130+
131+
An independent, non-singleton instance of the [Feature Flag API](#feature-flag-api) created via a factory function. Each isolated instance maintains its own state, including providers, evaluation context, hooks, and event handlers. Isolated instances do not share state with the global singleton or with each other. Intended for advanced use cases such as micro-frontend architectures, dependency injection frameworks, and testing scenarios.
132+
128133
### Integration
129134

130135
An SDK-compliant secondary function that is abstracted by the Feature Flag API, and requires only minimal configuration by the Application Author. Examples include telemetry, tracking, custom logging and monitoring.

specification/sections/01-flag-evaluation.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,54 @@ see: [error codes](../types.md#error-code)
530530
> The client's `provider status` accessor **MUST** indicate `NOT_READY` once the `shutdown` function of the associated provider terminates.
531531
532532
Regardless of the success of the provider's `shutdown` function, the `provider status` should convey the provider is no longer ready to use once the shutdown function terminates.
533+
534+
### 1.8. Isolated API Instances
535+
536+
[![experimental](https://img.shields.io/static/v1?label=Status&message=experimental&color=orange)](https://github.com/open-feature/spec/tree/main/specification#experimental)
537+
538+
While the `API` [functions as a global singleton](#requirement-111) in the default case, certain use cases require independent instances of the `API` with fully isolated state. Examples include micro-frontend architectures (where separately developed applications coexist in a single runtime), dependency injection frameworks and IoC containers (which manage object lifecycles outside the singleton's scope), testing scenarios (where parallel tests mutating shared state can interfere with each other), and server-side applications composed of multiple submodules each requiring distinct providers.
539+
540+
#### Requirement 1.8.1
541+
542+
> The `API` **MUST** expose a factory function which creates and returns a new, independent instance of the `API`.
543+
544+
Each instance returned by this factory function maintains its own state, including providers, `evaluation context`, hooks, event handlers, and transaction context propagators.
545+
Instances created by the factory function do not share state with the "default" global singleton or with each other.
546+
547+
```java
548+
// example factory function
549+
OpenFeatureAPI isolated = createIsolatedOpenFeatureAPI();
550+
isolated.setProvider(new MyProvider());
551+
Client client = isolated.getClient();
552+
```
553+
554+
See [application integrator](../glossary.md#application-integrator), [isolated API instance](../glossary.md#isolated-api-instance) for details.
555+
556+
#### Requirement 1.8.2
557+
558+
> Instances returned by the factory function **MUST** conform to the same `API` contract as the global singleton, including flag evaluation, provider management, context, hooks, events, and shutdown functionality.
559+
560+
An isolated `API` instance is functionally equivalent to the global singleton, but with independent state.
561+
Application code which uses a `client` obtained from an isolated instance behaves identically to code using a `client` from the global singleton.
562+
563+
#### Requirement 1.8.3
564+
565+
> The factory function for creating isolated instances **SHOULD** be housed in a distinct module, import path, package, or namespace from the global singleton `API`.
566+
567+
The factory function should be intentionally less discoverable than the default singleton, reducing the risk of `application authors` inadvertently creating isolated instances when the singleton would be more appropriate.
568+
The distinct import path serves as an explicit signal that the consumer is opting into advanced, non-default behavior.
569+
570+
```typescript
571+
// example: the factory function is accessed from a distinct module
572+
import { createIsolatedOpenFeatureAPI } from '@openfeature/web-sdk/isolated';
573+
```
574+
575+
#### Requirement 1.8.4
576+
577+
> A `provider` instance **SHOULD NOT** be registered with more than one `API` instance simultaneously.
578+
579+
Because the `API` instance manages the [lifecycle](./02-providers.md) of its associated providers (including initialization, shutdown, and event handling), binding a `provider` to more than one `API` instance could result in undefined behavior.
580+
A `provider` instance can be registered with multiple `domains` within a single `API` instance.
581+
When a provider is no longer associated with an `API` instance, it can be registered to another.
582+
583+
See [setting a provider](#setting-a-provider), [domain](../glossary.md#domain) for details.

0 commit comments

Comments
 (0)