Skip to content
intermediate Phase · Amazon Interview Preparation

Database Questions

Database design and optimization interview questions.

1h
10 problems
Topic Progress 0%

Database Design

SQL vs NoSQL

Aspect SQL NoSQL
Schema Fixed Flexible
ACID Yes Varies
Scaling Vertical Horizontal

Normalization

1NF: Atomic values
2NF: No partial dependencies
3NF: No transitive dependencies

When to Denormalize

  • Read-heavy workloads
  • Complex JOINs hurt performance

Key Points

  • Understanding Database Questions is essential for production systems
  • Always consider scalability and maintainability
  • Test thoroughly before deploying to production
  • Monitor performance and set up alerting

Common Patterns

  1. Validation: Always validate input at the boundary
  2. Error Handling: Use structured error responses
  3. Logging: Log key events for debugging
  4. Testing: Unit, integration, and load tests
  5. Documentation: Keep docs updated with code changes

Indexing & Optimization

Index Types

B-tree: Range queries (default)
Hash: Equality only
GIN: Full-text, JSONB
GiST: Geospatial

EXPLAIN ANALYZE

Shows: sequential scan, rows removed, execution time
Identifies: missing indexes, slow queries

Optimization Steps

  1. EXPLAIN ANALYZE
  2. Add indexes
  3. Rewrite queries
  4. Connection pooling
  5. Caching

Key Points

  • Understanding Database Questions is essential for production systems
  • Always consider scalability and maintainability
  • Test thoroughly before deploying to production
  • Monitor performance and set up alerting

Common Patterns

  1. Validation: Always validate input at the boundary
  2. Error Handling: Use structured error responses
  3. Logging: Log key events for debugging
  4. Testing: Unit, integration, and load tests
  5. Documentation: Keep docs updated with code changes

Transactions

ACID

Atomicity, Consistency, Isolation, Durability

Isolation Levels

Level Dirty Read Phantom
READ_COMMITTED No Yes
REPEATABLE_READ No No
SERIALIZABLE No No

Locking

  • Pessimistic: SELECT FOR UPDATE
  • Optimistic: version check

Key Points

  • Understanding Database Questions is essential for production systems
  • Always consider scalability and maintainability
  • Test thoroughly before deploying to production
  • Monitor performance and set up alerting

Common Patterns

  1. Validation: Always validate input at the boundary
  2. Error Handling: Use structured error responses
  3. Logging: Log key events for debugging
  4. Testing: Unit, integration, and load tests
  5. Documentation: Keep docs updated with code changes

Practice Problems

0 / 3 solved
Implement Database Questions

Design and implement a solution for Database Questions in a backend system. Consider scalability, error handling, and production readiness.

Solution
// Database Questions implementation
// Key aspects: validation, error handling, logging, testing

public class DatabaseQuestions {
    // Production-ready implementation
}
Database Questions Edge Cases

Identify and handle edge cases for Database Questions. What happens under high load, with invalid input, or during failures?

Solution
// Edge case handling:
// 1. Null/empty input -> validation
// 2. High load -> rate limiting, queuing
// 3. Failures -> retries, circuit breaker
// 4. Concurrent access -> locks, idempotency
Database Questions Testing Strategy

Write a testing strategy for Database Questions. Include unit tests, integration tests, and performance tests.

Solution
// Test plan:
// - Unit: 80% coverage target
// - Integration: API contracts
// - Performance: latency, throughput
// - Chaos: failure injection

Quiz

1. When to denormalize?

Question 1 options

2. Isolation level preventing phantom reads?

Question 2 options

3. What is a common mistake when implementing Database Questions?

Question 3 options

Flashcards

Question

ACID properties?

Answer

Atomicity, Consistency, Isolation, Durability

Question

Optimistic vs pessimistic locking?

Answer

Optimistic: version check. Pessimistic: row lock

Question

Database Questions best practices

Answer

Follow SOLID principles, write clean code, test thoroughly, document decisions, and monitor in production.

Revision Notes

Key Takeaways

  • 1. Normalize to 3NF, denormalize for reads
  • 2. Index columns in WHERE/JOIN/ORDER BY
  • 3. EXPLAIN ANALYZE to diagnose slow queries
  • 4. SERIALIZABLE prevents all concurrency issues

Interview Tips

  • Design schema for real scenario
  • Walk through EXPLAIN output
  • Discuss ACID and isolation levels

Cheat Sheet

Database Interview

  • Normalize: 3NF
  • Index: B-tree, Hash, GIN, GiST
  • ACID: Atomicity, Consistency, Isolation, Durability
  • Locking: Pessimistic (SELECT FOR UPDATE) vs Optimistic (version)