The Data Layer
Services need to store state. In a modern architecture, we don't just dump everything into one giant SQL database. We use the right tool for the job.
Types of Data Stores
-
Relational Databases (SQL):
- Examples: PostgreSQL, MySQL.
- Use Case: Structured data with strict relationships (e.g., Users, Orders, Financial transactions).
- HA Strategy: Master-Slave replication. Writes go to Master, reads can be spread across Slaves.
-
NoSQL Databases:
- Examples: MongoDB, Cassandra.
- Use Case: Unstructured data, massive scale, high write throughput (e.g., Social media feeds, IoT sensor data).
-
In-Memory Caches:
- Examples: Redis, Memcached.
- Use Case: Storing frequently accessed data in RAM for sub-millisecond access (e.g., Session tokens, Leaderboards).
Polyglot Persistence
This approach of using multiple database technologies within a single system is called Polyglot Persistence. It allows each service to be highly optimized for its specific data access patterns.