Skip to content
Tutorials Center
My learning

Topics

Lesson 41 of 42 ยท Practice and Review

Magento Interview Questions

Prepare for a Magento developer interview: concise answers on architecture, dependency injection, plugins, events, EAV, indexers and caching, with two runnable stand-ins.

A Magento interview usually mixes two kinds of questions: concept questions ("what is the difference between a plugin and a preference?") and judgment questions ("how would you add a field to products without breaking upgrades?"). Interviewers care less about memorized trivia than about whether you know why Magento is built the way it is and which tool fits which job.

This lesson collects common questions with short answers, grouped by topic and linked back to the lessons that explain each idea in depth. Where a detail depends on the exact 2.4.x version, the answer says so. Magento cannot run on this site, so real PHP and XML here are read-only, and the two runnable examples at the end are plain-PHP stand-ins (a changelog-based indexer and a tagged cache), not Magento code. The best way to use the page is to cover the answers, say yours out loud, and then compare.

flowchart TD
    Q["Interview topics"] --> A["Architecture<br/>modules, areas, modes"]
    Q --> B["Dependency injection<br/>preferences, virtual types"]
    Q --> C["Extending<br/>plugins and observers"]
    Q --> D["Data<br/>EAV, collections, schema"]
    Q --> E["Operations<br/>indexers, caching, deployment"]

The five areas that cover most Magento interviews.

Architecture

What is the difference between Magento Open Source and Adobe Commerce?

Open Source is the free core platform. Adobe Commerce is the paid edition that adds features such as staging, B2B functionality and extra support or cloud options, and its feature set can change by version. Both share the same development model, so the techniques in this track apply to both. See What Magento Is and Where It Fits.

How is Magento organized?

As modules. Almost every feature, including core ones, lives in a module with a registration.php and an etc/module.xml. Custom code goes in app/code/Vendor/Module (or, for Composer-installed packages, under vendor/). Themes live in app/design. See Architecture and Directory Layout.

What are areas?

Separate contexts with their own configuration: frontend, adminhtml, webapi_rest, webapi_soap, graphql, crontab and base/global. A file such as etc/frontend/di.xml applies only to the storefront and is merged on top of the global etc/di.xml. See Areas and Configuration Files.

What are the deploy modes?

developer (errors shown, code generated on demand, static files created on the fly), production (optimized; generated code and static content must be prepared in advance, errors hidden) and default (an in-between mode not intended for serious use). Production is the only mode for live stores. See Deployment and Upgrades.

Why does module load order matter, and how do you control it?

Configuration from several modules is merged, so who loads first affects the result. You declare <sequence> in module.xml (and Composer dependencies in composer.json) so your module loads after the modules whose config you extend. See Module Sequence and Dependencies.

Dependency injection

Why should you not use the ObjectManager directly?

It hides dependencies, makes code hard to test and bypasses the structure the framework relies on. Ask for what you need in the constructor and let Magento inject it. Direct ObjectManager use is acceptable only in rare framework-level or legacy glue. See The Object Manager and Constructor Injection.

What is a preference?

A di.xml instruction that says "whenever someone asks for this interface or class, give them that class instead". It is how interfaces get implementations, and also how you can replace a core class. Only one preference wins per type, so overriding the same class in two modules conflicts. See Preferences and Interfaces in di.xml.

What is a virtual type?

A named configuration of an existing class with different constructor arguments, declared in di.xml without writing a new PHP class. It is useful when the same class should behave differently in different places. See Virtual Types and Constructor Arguments.

What are factories and proxies?

A factory is a generated class (ProductFactory) with a create() method that returns a new instance of a non-shared object such as a model. A proxy is a generated stand-in for a heavy dependency that only builds the real object when a method is first called, which avoids paying for it on every request. See Factories, Proxies and Generated Code.

Plugins and events

What are the three plugin method types?

before (change the arguments), around (wrap the call; you decide whether to call $proceed) and after (change the result). They are declared in di.xml with a name, a class and an optional sortOrder. See Plugins (Interceptors).

What cannot be intercepted?

Final classes and final methods, static methods, non-public methods and constructors, and objects created before the interception framework is available. If you need to change such code, you may need a preference or an observer instead.

Why are around plugins discouraged?

They increase the call stack, make ordering harder to reason about and, if they forget to call $proceed, silently remove the original behavior for every plugin below. Use before or after plugins when they are enough. See Plugin Best Practices and Pitfalls.

Plugin or preference?

A plugin changes one method and cooperates with other plugins. A preference replaces the whole class, and only one can win. Prefer plugins; use a preference when you must change many methods or there is no suitable public method.

Plugin or observer?

Observers react to events that someone chose to dispatch and cannot change return values; plugins hook any public method and can. Use an observer to react (log, notify, queue work), a plugin to change behavior. See Events and Observers.

Why keep observers lightweight?

They run inside the request that triggered the event, and an exception in them travels back into the dispatching code. Heavy work should go to a queue. See Project: Order Events and Notifications.

Requests and output

Describe the flow of a storefront request.

The web server sends the request to pub/index.php, which bootstraps the application. The front controller asks the routers to match the URL (frontName, controller, action) to an action class. The action returns a result object, often a page result whose layout is built from merged layout XML. Blocks and templates render the HTML, and the response is sent, possibly stored in the full page cache. See Routing and Controllers.

Block, ViewModel, template: who does what?

The template (.phtml) outputs markup. A ViewModel holds presentation logic and is passed as an argument from layout XML; it is the modern way to keep blocks thin. Blocks remain the framework glue. All output must be escaped with the Escaper. See Blocks, ViewModels and PHTML Templates.

What is a layout handle?

A name for a set of layout instructions loaded for a page, such as catalog_product_view. Instructions from all modules and themes for the same handle are merged. See Layout XML and Handles.

Data

What is EAV and why does Magento use it?

Entity-Attribute-Value stores each attribute's values in separate typed tables (varchar, int, decimal, text, datetime) keyed by entity, attribute and store. It makes it easy to add attributes without altering table structure and supports per-store values, at the cost of complex joins. To keep storefront reads fast, Magento relies on indexes and flat or search-engine data. See EAV: Entity-Attribute-Value.

How do you add a product attribute correctly?

Through a data patch that uses EavSetup, never by editing tables by hand, so it is versioned and repeatable. See Data Patches and Schema Patches and Project: Extending Products with a Custom Attribute.

What is declarative schema?

db_schema.xml describes the desired tables, columns and constraints; Magento compares it to the database and applies the difference. It replaces most hand-written install and upgrade scripts. See Declarative Schema.

Model, resource model, collection?

The model holds the data and business behavior of one entity. The resource model talks to the database for it (load, save, delete). The collection loads many entities and supports filters, sorting and paging. See Models, Resource Models and Collections.

Why use repositories and service contracts?

They give a stable, versioned API (interfaces) that other modules and the REST/GraphQL layers can depend on, even if your model internals change. Direct model use in business code ties it to storage details. See Service Contracts and Repositories.

getSize() versus count() on a collection?

getSize() runs a count query for all matches regardless of paging; count() counts the items loaded in the current page. A common bug is calling count() to show total results.

What causes an N+1 problem in Magento code?

Loading a collection and then loading something per row inside a loop (for example loading each product by id). Fix it with joins, collection-level attribute selection or by loading related data in one query. See Performance and Security.

APIs, admin and background work

How do you create a REST endpoint?

Define a service interface with accurate docblocks, add a preference, declare the route in webapi.xml with an ACL resource, and define that resource in acl.xml. See The REST API and Project: A REST Integration Endpoint.

How are admin pages protected?

Admin controllers declare an ADMIN_RESOURCE that must exist in acl.xml, and admin URLs include a secret key. Roles are granted ACL resources. See Admin Controllers, Menus and ACL.

Cron versus queue?

Cron runs code on a schedule, from crontab.xml, and needs the system cron to call Magento. A message queue runs code in response to a published message, with a consumer. Use cron for periodic jobs and queues for work triggered by events. See Cron Jobs and Message Queues.

Indexers and caching

What does an indexer do?

It precomputes data that would be expensive to build on every request, such as prices, category-product relations and search data. Indexers run in Update on Save mode (changed data is reindexed immediately) or Update by Schedule mode (changes are recorded and processed in batches by cron).

How does Update by Schedule know what changed?

Database triggers (the materialized view, or mview, mechanism) write changed entity ids into changelog tables, and a cron job reindexes only those ids. The first stand-in below imitates the idea.

What are cache types, tags and the full page cache?

Cache types are groups such as configuration, layout, block HTML and full page. Entries can carry tags, so saving a product can invalidate exactly the entries tagged with that product. The full page cache stores whole pages, built-in or in Varnish. The second stand-in imitates tag-based invalidation. See Indexers and Caching.

cache:clean or cache:flush?

cache:clean removes Magento's own cache entries by type. cache:flush empties the whole cache storage, which may also remove data from other applications sharing it. Prefer clean unless you really need flush.

Quality and security

How do you protect against XSS, CSRF and SQL injection?

Escape output with the Escaper methods that match the context, use form keys on forms that change state, and use bound parameters or the collection/resource APIs instead of building SQL strings. Check ACL on every admin and API entry point.

How do you test Magento code?

Unit tests with PHPUnit and mocked dependencies for logic, integration tests against a real test database and framework, API-functional tests for endpoints, and MFTF for browser-driven acceptance. See Testing Magento Code.

What do you check before upgrading Magento?

Composer constraints, extension compatibility with the target version, deprecated APIs in your code, then run setup:upgrade, setup:di:compile and static content deployment in a staging environment before production. See Deployment and Upgrades.

Stand-in 1: an indexer driven by a changelog

In "by schedule" mode real Magento records changes through database triggers and processes them in batches. This stand-in uses SQLite and PHP calls instead of triggers. It shows why the second run reindexes only a few rows.

PHP Update by Schedule with a changelog

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Product 2 was saved twice, but the changelog is read with DISTINCT, so it is reindexed once. A run with no changes does no work.

Stand-in 2: cache tags and invalidation

This tiny cache stores values with tags and removes everything carrying a tag, which is how saving one product can clear every page that displayed it. Tag names such as cat_p_<id> follow a Magento convention for products, but this is not Magento's cache.

PHP A cache with tags

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Only the three pages that showed product 2 were rebuilt; the chair page stayed cached. That precision is why tags beat flushing everything.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which statement about around plugins is the best interview answer?

    Before and after plugins cover most needs with less risk. Around plugins are for cases where you must control whether the original runs.
  2. 2. A product is saved twice before cron runs in Update by Schedule mode. How many times is it reindexed in the next run?

    The changelog may contain the id twice, but the indexer processes each distinct entity id once per run.
  3. 3. What is the difference between getSize() and count() on a collection?

    getSize() runs a separate count query, while count() works on what has been loaded for the current page.
  4. 4. Why use cache tags?

    Tags let a product save remove exactly the cached pages and blocks that displayed that product.
  5. 5. Which tool is right for changing the return value of one public method?

    Observers cannot change return values. A before or after plugin changes arguments or results of a public method.

Summary

  • Know the building blocks: modules, areas, deploy modes and the request flow.
  • Prefer constructor injection, plugins and observers over the ObjectManager and class replacement.
  • Explain EAV, declarative schema, models, resource models, collections and repositories, and why each exists.
  • Understand indexer modes and cache tags: both exist to avoid doing expensive work on every request.
  • Mention testing, ACL, escaping and bound parameters when asked about quality or security.

When you want a quick lookup of commands and file locations, continue with the Magento Cheat Sheet.