Transactional (OLTP) vs Analytical (OLAP) Databases
The two families of database answer different questions and are tuned for different access patterns. Choosing the wrong one shows up as either slow reports or a system that cannot keep up with its own writes.
Transactional databases (OLTP — online transaction processing)
Section titled “Transactional databases (OLTP — online transaction processing)”- Handle day-to-day transactions and real-time operations.
- Are optimised for fast, small read and write operations.
- Maintain data consistency through ACID properties — atomicity, consistency, isolation, durability.
- Typically use normalised data structures to minimise redundancy.
- Serve use cases such as banking transactions, order processing and inventory management.
- Hold current, in-the-moment data.
- Are designed for many concurrent users each making a small change.
Analytical databases (OLAP — online analytical processing)
Section titled “Analytical databases (OLAP — online analytical processing)”- Are built for business analysis and decision support.
- Are optimised for complex queries and large-scale aggregation.
- Focus on analysis and reporting rather than transaction processing.
- Often use denormalised structures so that queries touch fewer joins.
- Serve use cases such as business intelligence, trend analysis and forecasting.
- Hold historical data spanning long time periods.
- Are designed for fewer users running complex queries over large datasets.
Note the naming trap: an operational database is the transactional one — the store the running business writes to. OLAP is the analytical side, fed from it.
Common architectural patterns
Section titled “Common architectural patterns”For transactional databases
Section titled “For transactional databases”- Primary–replica
- The primary node handles writes.
- Multiple read replicas scale reads.
- Replication is synchronous or asynchronous, which decides whether a replica can serve a read immediately after a write.
- Sharding
- Data is distributed across multiple nodes.
- Horizontal partitioning by key range or hash value.
- Each shard owns a subset of the total data.
For analytical databases
Section titled “For analytical databases”- Star schema
- Fact tables in the centre.
- Dimension tables around the edges.
- Optimised for analytical queries.
- Data lake
- Raw data stored as it arrives.
- Schema applied on read rather than on write.
- Multiple processing engines over the same storage.
- Lambda architecture
- A batch processing layer.
- A speed layer for real-time processing.
- A serving layer that answers queries from both.
The star schema
Section titled “The star schema”A star schema classifies every table as either a fact table or a dimension table. Fact tables store observations — sales, balances, readings — as numeric measures plus the keys of the dimensions that describe them. Dimension tables describe the business entities those keys point at.
Key characteristics:
- Central fact table
- Holds the business metrics.
- Carries foreign keys to every dimension table.
- Measures are typically numeric and additive.
- Dimension tables
- Hold descriptive attributes.
- Are joined to the fact table by their primary keys.
- Are denormalised for query performance.
- Advantages
- Simple to understand and navigate.
- Well suited to OLAP queries.
- Efficient for aggregations and joins.
- Typical uses
- Sales analysis
- Financial reporting
- Inventory management
- Customer behaviour analysis
A snowflake schema is the variation in which dimension tables are themselves normalised into further tables. It reduces redundancy at the cost of longer join chains, and is generally worth it only for very large dimensions.
Resources
Section titled “Resources”Transactional (OLTP):
- PostgreSQL — High Availability, Load Balancing and Replication
- MySQL — Replication
- SQL Server — Always On availability groups
Analytical (OLAP):
- Apache Hadoop documentation
- Snowflake — key concepts and architecture
- Amazon Redshift — system and architecture overview
- Understand star schema and its importance — Microsoft’s guidance, the most complete free write-up of the model