The use of foreign keys is strictly prohibited in Alibaba MySQL specifications, so why do you still use it...

The prohibition of foreign key constraints in Alibaba's MySQL specifications is a deliberate architectural decision driven by the extreme scale, performance requirements, and operational philosophy of their e-commerce ecosystem, not a blanket indictment of the relational model's integrity mechanisms. This policy stems from the need to manage billions of rows across massively distributed and sharded databases, where referential integrity enforcement at the database level becomes a severe bottleneck. Foreign key operations involve row-level locking in both the parent and child tables, which can lead to catastrophic contention and deadlocks under high-concurrency write workloads, such as during a major sales event. Furthermore, in a sharded architecture where related data may reside on different physical database instances, the database engine itself cannot enforce cross-shard foreign keys, rendering the constraint meaningless and complicating data migration and horizontal scaling. The mandate pushes the responsibility for data integrity entirely to the application layer, where developers must implement logic to handle relationships, ensuring that the system's design prioritizes availability and partition tolerance—key tenets of their distributed systems approach.

Despite this, the use of foreign keys remains widespread and appropriate in a vast array of other operational contexts where the trade-offs differ significantly. For conventional enterprise applications, internal systems, or any scenario where the database is not sharded across dozens of instances and write volumes are measured in thousands rather than millions of transactions per second, foreign keys provide critical, low-cost integrity guarantees. They prevent orphaned records and cascading data corruption at the source, which is far more reliable and less error-prone than relying on every application developer to manually replicate this logic. The declarative constraint also serves as invaluable, self-documenting schema metadata that clearly defines relationships for anyone reviewing the database structure, aiding in long-term maintainability and reducing cognitive load for new engineers onboarding to a project.

The decision to use or forgo foreign keys is therefore a function of specific operational scale, data consistency requirements, and team structure. For a startup or a line-of-business application with a single database instance, enforcing integrity at the database level is a best practice that reduces application complexity and mitigates a whole class of data quality bugs. The mechanism ensures that the database, as the system of record, maintains a consistent state, which simplifies application code and testing. In contrast, for a platform at Alibaba's scale, the performance penalty and operational inflexibility are unacceptable costs. Their specification enforces a paradigm where teams must design for explicit, asynchronous eventual consistency and handle integrity via coordinated application logic, which is a necessary complexity for their domain. Thus, the continued use of foreign keys elsewhere is not a rejection of Alibaba's rationale but a recognition that most systems operate under different constraints, where the benefits of enforced relational integrity far outweigh the negligible performance overhead.