Skip to content

Database Systems Overview

This section provides an in-depth look at the various database systems utilized across Komerce’s infrastructure. Databases are the backbone of our applications, storing critical business data and ensuring its integrity, availability, and performance.

Our strategy involves using the right database for the right job, balancing relational and NoSQL solutions to meet diverse application requirements.

Komerce employs a variety of database technologies, each selected for specific use cases:

  • PostgreSQL (Relational Database):

    • Use Cases: Core business data (e.g., orders, user profiles, product catalogs), financial transactions, and any data requiring strong ACID compliance and complex relational queries.
    • Key Features: Robustness, extensibility, strong data integrity, support for complex joins and transactions.
  • MongoDB (NoSQL Document Database):

    • Use Cases: User authentication and authorization data, content management, real-time analytics, and data with flexible or evolving schemas.
    • Key Features: High scalability, flexibility (schemaless), high performance for large volumes of data, easy horizontal scaling.
  • Redis (In-Memory Data Store / Cache):

    • Use Cases: Caching frequently accessed data, session management, real-time leaderboards, message queues, and pub/sub systems.
    • Key Features: Extremely fast read/write operations, support for various data structures (strings, hashes, lists, sets, sorted sets).

3. Database Architecture & Replication Strategies

Section titled “3. Database Architecture & Replication Strategies”

To ensure high availability, fault tolerance, and read scalability, our production databases are configured with robust replication strategies.

Our PostgreSQL instances typically follow a primary-replica (formerly master-slave) architecture. This setup provides:

  • High Availability: If the primary instance fails, a replica can be promoted to become the new primary.
  • Read Scalability: Read-heavy workloads can be distributed across multiple replica instances.
  • Data Durability: Replicas maintain copies of the data, protecting against data loss.
graph TD
A[Application Service] --> B(Primary PostgreSQL)
B --> C(Replica PostgreSQL 1)
B --> D(Replica PostgreSQL 2)
C --> E[Read-Only Workloads]
D --> F[Read-Only Workloads]
subgraph PostgreSQL Cluster
B
C
D
end
style PostgreSQL Cluster fill:#f9f,stroke:#333,stroke-width:2px

MongoDB instances are deployed as replica sets, which are groups of mongod processes that maintain the same data set. A replica set provides redundancy and high availability.

  • Primary: Receives all write operations.
  • Secondaries: Replicate the primary’s oplog and apply the operations to their data sets, ensuring data consistency.
graph TD
A[Application Service] --> B(MongoDB Primary)
B --> C(MongoDB Secondary 1)
B --> D(MongoDB Secondary 2)
subgraph MongoDB Replica Set
B
C
D
end
style MongoDB Replica Set fill:#ccf,stroke:#333,stroke-width:2px

Redis instances are typically deployed with Sentinel for high availability or as a Cluster for sharding and scalability.

  • Sentinel: Provides monitoring, notification, and automatic failover for Redis instances.
  • Cluster: Distributes data across multiple Redis nodes, allowing for horizontal scaling.

Regular and automated backup procedures are in place for all production databases to ensure data recoverability in case of disaster or accidental data loss.

  • Frequency: Daily full backups, with incremental backups throughout the day.
  • Retention: Backups are retained for [X days/weeks/months] based on data criticality and compliance requirements.
  • Storage: Backups are stored securely in [Cloud Storage Service] with appropriate encryption.
  • Recovery Point Objective (RPO) & Recovery Time Objective (RTO): Defined for each critical database to guide recovery efforts.

Database security is paramount. We adhere to the following practices:

  • Network Isolation: Databases are deployed in private subnets, accessible only from authorized application servers.
  • Authentication & Authorization: Strong authentication mechanisms and least-privilege access control are enforced for all database users.
  • Encryption: Data at rest (storage encryption) and data in transit (SSL/TLS for connections) are encrypted.
  • Auditing & Logging: Database activity is logged and monitored for suspicious behavior.
  • Regular Patching: Database software is regularly updated to address security vulnerabilities.

Comprehensive monitoring is implemented for all database instances to track performance, health, and resource utilization. Key metrics include:

  • CPU Utilization
  • Memory Usage
  • Disk I/O
  • Connection Count
  • Query Latency
  • Replication Lag

Alerts are configured for critical thresholds to ensure proactive issue resolution.