Hello to everyone! Today I want to ask y`all a question and maybe affect the way how you interacts with Magento on daily basis.
Most likely you worked with Magento product attributes (EAV – Entity Attribute Value) thousands times – created them/changed labels/added some options to complex attributes. But let me guess! Did you do all of this on production? If yes – I have bad news for you. From the times EAV was added to Magento it was always not recommended to create or modify them directly in admin. Yes it is possible. Yes Magento added this like a killer-feature. So why it is not recommended?
First reason – performance. Of course this affects only “production that is in production” (dev/staging/UAT or production with 2 visitors doesnt have this kind of issue). Let`s say you want to add your «Color» attribute to Catalog Navigation. You are going to admin, searching for your color attribute, and choosing «Show In Layered Navigation». And thats all? Of course not. Everything that is related to Catalog on frontend (mostly product and categories) Magento takes from special data sets (indexer tables). But everything you do in admin Magento puts into separate data sets (EAV tables). So when you change something Magento needs to synchronize data between indexer tables and EAV tables. And this is sometimes harder than launch Tesla into space. And of course this synchronization (let`s call it “reindexation”) eats a lot of resources. Next thing you need to keep in mind is cache. Your data becomes invalid, so Magento needs to flush all caches (cause caches become invalid as well). But will your store becomes faster without caches? I don`t think so! So if your bill for AWS become bigger from month to month and you notice slowness, maybe it is because of this?
Second reason – consistency gap. If you will add 20 attributes on production but disregard to do the same on staging and dev will you be able to test content on staging?
So what is the alternative? It can be weird but Magento treats Product/Category Attributes not like data but like a part of code. So logically all changes to attributes should be done ONLY on the code level and should be deployed to the server. You can find the way how to do this in native Magento article: https://devdocs.magento.com/videos/fundamentals/add-new-product-attribute/.