ClickMasters
← Back to all FAQ cards

Database & Data Management

SQL & NoSQL Database Solutions FAQs

When should I use PostgreSQL vs MongoDB?

PostgreSQL is the correct default for the majority of B2B applications. Use PostgreSQL when: data has relationships (users belong to organisations, orders have line items, invoices belong to customers relational structure that needs joins), data consistency is critical (ACID transactions ensure that related data is always in a consistent state a payment cannot be recorded without an order, or must be rolled back together), the data model is relatively stable (relational schemas are more rigid but produce more predictable, maintainable code), or multi-tenancy is a requirement (PostgreSQL's row-level security is uniquely suited to SaaS multi-tenancy). Use MongoDB when: the data model is genuinely document-oriented with variable schemas (different product types have fundamentally different attributes no fixed column schema), the data is read and written as complete documents (no need to join across entities), or horizontal write scaling is needed (MongoDB's sharding scales writes across multiple nodes PostgreSQL requires more complex solutions for write-heavy horizontal scaling).

What is the difference between Redis caching and application caching?

Redis caching stores computed results in a shared, in-memory data store that all application instances can access. Application caching stores results in the memory of a single process. The key difference: application (in-process) caching does not survive process restarts, is not shared across multiple API server instances (each instance maintains its own cache independently), and uses the application's own memory increasing the application's memory footprint. Redis caching is persistent across deployments, shared across all application instances (all 20 API server replicas hit the same Redis cache), and isolated in a separate process. For any application running more than one instance, Redis is the correct caching layer application caching produces inconsistent behaviour (instance A has a cached result, instance B does not) and cache invalidation problems (invalidating the cache requires clearing it on every instance separately).

What is DynamoDB's single-table design and why is it controversial?

DynamoDB's single-table design is an architectural pattern where all entity types (users, orders, products, sessions) are stored in a single DynamoDB table differentiated by their primary key prefix and sort key structure. The rationale: DynamoDB is optimised for single key-value lookups and range queries on the sort key; joins across tables require two separate reads at the application level. By placing all related entities in the same table with carefully designed sort key structures, you can retrieve a user and all their orders in a single table query. The controversy: single-table design requires knowing all access patterns at design time (it is very difficult to add new access patterns post-launch without a full reindex), it is counterintuitive to relational database thinking (requires a mental model shift), and it makes the data harder to inspect and debug. ClickMasters uses single-table design for DynamoDB when the access patterns are well-defined and stable, and recommends PostgreSQL when access patterns are exploratory or likely to evolve.

What is polyglot persistence and when does it make sense?

Polyglot persistence is the architectural approach of using multiple database technologies each selected based on the specific requirements of the data it stores. A typical polyglot stack for a B2B SaaS product: PostgreSQL for transactional data (user accounts, billing, application state), Redis for caching and queues (hot data, session tokens, background job queues), Elasticsearch for search (indexed from PostgreSQL via CDC users search products, support agents search tickets), and ClickHouse for analytics (event data from Kafka, aggregations that would be too expensive in PostgreSQL). The benefit: each database is used for what it does best. The cost: operational complexity (multiple database technologies to monitor, back up, scale, and update), data synchronisation (changes in the primary database must propagate to derived databases CDC pipelines, consistency delays), and developer expertise (the team needs proficiency in multiple database technologies). Polyglot persistence pays off at scale; for smaller teams and products, PostgreSQL with Redis is sufficient for the majority of use cases.