SQL Database Basics in System Architecture
medium · System Architecture
SQL Database Foundations Relational Database Management Systems (RDBMS) are the backbone of most enterprise applications, providing structured data storage, complex querying capabilities, and robust data integrity guarantees. 1. MySQL vs. PostgreSQL While both are industry-standard open-source relational databases, they serve different architectural needs. Feature MySQL PostgreSQL Philosophy Lightweight, high-read performance, easy to set up. Highly extensible, complex query powerhouse, feature-rich. ACID Compliance Supported via InnoDB storage engine. Native and fully compliant in all configurations. Performance Faster for simple read-heavy web workloads. Better for complex concurrent write operations (MVCC). Extensibility Limited; focused on simplicity. High; supports custom data types, operators, and languages. Best Use Case Web development, CMS, simple prototypes. Enterprise systems, data warehousing, GIS, complex apps. 2. Database Transactions A transaction is a sequence of one or more SQL operations treated as a single, atomic "unit of work. " If your application needs to transfer money between two accounts, you must debit one account and credit another. You cannot have one operation succeed while the other fails. A transaction ensures these two steps succeed together or not at all. START TRANSACTION : Signals the database to group subsequent operations. COMMIT : Saves all changes made during the transaction permanently to the disk. ROLLBACK : Aborts the transaction and discards all changes, returning the database to its state before the transaction began. 3. The ACID Properties The ACID framework defines the gold standard for reliable database transactions, guaranteeing data integrity even during system failures or concurrent access. Atomicity ("All or Nothing"): Transactions are indivisible. Either every operation within the transaction completes successfully, or the entire transaction fails and the database remains unchanged. Consistency ("Valid State"): A transaction must move the database from one valid state to another. It ensures that all data follows defined rules, constraints, triggers