ddtcorex

02 Jul 2026 · 2 min read

Magento 2 events vs plugins: when to use which

Two ways to change Magento 2 behavior without touching core — plugins and event observers. Here is the decision framework the core team actually uses.

In the last post we met plugins. Magento 2 has a second, equally important extension mechanism: events and observers. Knowing which to reach for is a core engineering skill.

Events and observers

Magento dispatches events at meaningful moments — sales_order_place_after, customer_login, catalog_product_save_before, and hundreds more. You listen with an observer:

<event name="sales_order_place_after">
    <observer name="sync_to_erp" instance="Vendor\Module\Observer\SyncOrderToErp" />
</event>
class SyncOrderToErp implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        // fire-and-forget sync, no return value expected
    }
}

The decision framework

Situation Use
Change a method's inputs or return value Plugin
React to a lifecycle moment (something happened) Event
You need a return value honored by the caller Plugin (after/around)
Decoupled side effect (notify, log, sync) Event
The target is a private/protected method Event (plugins only intercept public)
Multiple independent behaviors on one action Event (loosely coupled)

Rule of thumb: if you would describe it as "do X after Y happens," use an event. If you would say "change what Y returns," use a plugin.

Performance note

around plugins wrap the original method and can hurt performance if they run on hot paths (e.g., product load in a listing). Prefer before/after over around, and prefer events when you don't need to alter the result. You can quantify the difference by profiling on a production-shaped local stack — Govard brings one up without hand-wired Dockerfiles.

What's next in this series

Both plugins and events operate on the backend. The storefront itself is built from layout XML and UI components — and with Hyva, that stack got dramatically lighter. Next, Luma vs Hyva and how the frontend is wired.

Next in this series: Layout XML & UI Components — Luma vs Hyva — /blog/magento2-layout-hyva

magento2eventsplugins