Microkernel

Plug-in

Escrito por Darjus Kazakevic · revisado el

A small core that loads plug-ins; the plug-ins do the real work.

A microkernel app has two parts. A small core handles start-up, loading plug-ins and a few shared services. Everything users think of as a feature is a plug-in. VS Code is the best-known example: language support, Git tools, themes and debuggers are all extensions.

The hard work is the contract between core and plug-ins. Extension points are a public API: once others depend on them, changing them breaks real users. When a plug-in needs something the core does not offer, you either widen the API for everyone or let that plug-in reach past it. The second choice slowly destroys the pattern.

En esencia — Build every feature as a plug-in against a small, versioned API, so the core stays stable for years while features come and go.

Cuándo recurrir a él

Recurre a él cuando

  • Users or third parties extend the product: IDEs, editors, browsers
  • Different customers need different feature sets on one core
  • Features change often, but the core should stay stable for years

Reconsidéralo cuando

  • A fixed feature set that one team ships together
  • Features need deep access to each other's internals
  • You cannot promise to keep a public plug-in API stable

The parts

Core (the kernel)
The minimum the system needs to run: start-up, plug-in discovery and lifecycle, and a few shared services such as settings and logging. It never imports a specific plug-in.
Plug-in
A module that adds one feature through the core's API: a language server, a theme, a payment method. You can install, update and remove it without rebuilding the core.
Extension point and manifest
An extension point is a named place where plug-ins add behaviour, such as “commands”. A manifest (package.json in VS Code) declares which points a plug-in uses and when to load it.
Plug-in registry
Where the core tracks installed plug-ins, their versions and their state. It answers “who handles .py files?” without the core knowing any plug-in by name.

Reglas de diseño

Treat extension points as a public API
Version every hook and widen it on purpose, for everyone. Letting one plug-in reach past the contract into core internals is how a microkernel stops being one.
Contain every plug-in's failure
Run each plug-in inside its own error boundary, or outside the core process, as VS Code does with its extension host. One bad plug-in must not crash the core or the other plug-ins.
Load plug-ins lazily
Activate a plug-in only when it is needed, for example when a Python file opens. Loading 60 extensions at start-up makes even a small core slow.
Let plug-ins talk only through the core
Plug-ins communicate through core services or events, never by importing each other. Direct imports create hidden dependencies and a fixed load order.

Errores habituales

  • The core grows features “just this once”. Soon every new feature needs a core release.
  • Plug-ins importing core internals. Every core release then breaks some of them.
  • Loading every plug-in at start-up. Start-up time grows with each install.
  • No version check. An old plug-in crashes on a new core instead of being skipped.