Video in progress

How do you design extension points in an internal platform library used by ten teams?

I offer extension through small interfaces (SPIs), each with a clear contract and a default implementation, not through inheritance. To keep teams from depending on internal classes, I keep the public API narrow and close off the rest.

📖 Answer

The biggest risk for a platform library is that it becomes unable to change. If teams have overridden your protected method, you can no longer change it, because someone's prod would break. That's why you have to choose extension points deliberately.

The rules I apply:

Strategy/callback instead of template method. Instead of letting people extend AbstractKafkaConsumer, I ask for a MessageHandler<T> interface. Inheritance exposes both internal state and the lifecycle to the team; an interface exposes only one contract.

Small, precise SPIs. TenantResolver, AuditSink, RetryClassifier: each has one or two methods. There's a default implementation, and if a team provides its own bean, @ConditionalOnMissingBean replaces it.

Mark the public API clearly. internal packages, and if you use JPMS, exports only for the API package. Even without JPMS, I check the public surface on every release with ArchUnit or an API-diff tool (japicmp, revapi).

Behavior when hooks fail. If a team's AuditSink throws an exception, does the main flow stop? That has to be written in the contract. Often the answer is "no, we log it and increment a metric".

Versioning. Take semver seriously; a deprecated API lives for at least one minor version, with a migration guide. So that you can tell which version teams are on, the library emits its version as a metric at startup; that's how you find the ones stuck on an old version.

One more thing: I add an extension point not when the first team asks, but when at least two teams show a real need. An abstraction built for one customer is usually drawn in the wrong place.