Iām a fan of an SDK product pattern Iāve heard people call ābetter togetherā. The idea is for SDKs to be decoupled, but complementary.
An example is an SDK that needs telemetry. One approach would be to add telemetry to the SDK, but this has a few problems: bloat, opacity, redundancy and coupling. An app may already have a telemetry SDK installed, so bundling another with an unrelated SDK bloats the app. Data logged inside the SDK is opaque to the app, which also complicates any SDK billing story. If the SDK does want to export telemetry data, it will need to build telemetry-specific logic redundant to the appās telemetry provider. Any telemetry logic built by the SDK is coupled to the SDK.
The better-together pattern provides an alternative. To continue with the example above, an SDK requiring telemetry could detect if a telemetry provider is installed and publish events to it. A simplistic example would be to provide a method on the SDK to set a telemetry provider, eg:
class SDK {
constructor(telemetry = null);
ā¦
sayHi(){
if (telemetry) {
telemetry.logEvent(āsaid_hiā);
}
}
}
ā¦
telemetry = new Telemetry();
sdk = new SDK(telemetry);
sdk.sayHi();
With this approach telemetry is only included in the app if the app owner wants it, minimizing bloat. Telemetry from the SDK is visible alongside the appās other telemetry. The SDK can focus on whatever it does best. Telemetry is reusable elsewhere in the app.
One potential downside with this pattern concerns differentiating āinternalā use-cases. Continuing with the telemetry example, the SDK may want to log events that are unrelated to the appās functionality. Iāve seen three approaches: donāt differentiate, differentiate throughout, or donāt use the better-together pattern. The first approach treated all data as belonging to the app and namespaced all events published by the SDK, which worked well. The second approach was expensive due to technical complexity and eventually discontinued. The third approach was expensive due to redundant staffing, infra, UX, etc, but necessary so long as some parties don’t buy into the better-together pattern. I guess this stresses the “together” part of better-together š