Part 2 · ডেটাবেস 📖 ১২ মিনিট পড়া 📝 ২০টি কুইজ

Database — DBMS-এর ভিত্তি

প্রতিটি অ্যাপের হৃদয় — যেখানে সব তথ্য জমা থাকে।

📝 কুইজে যান

আপনার মাথায় একটা phone book কল্পনা করুন — নাম পাশে নম্বর, alphabetically সাজানো। কোনো নাম খুঁজলে দ্রুত পাওয়া যায়। নতুন entry যোগ, পুরাতন আপডেট, ভুল delete — সব করা যায়। এটাই একটি ছোট database। বাস্তবে Facebook-এর database-এ ৩ বিলিয়ন user-এর ডেটা — কিন্তু concept একই।

Database কী?

Database হলো organized data-র সংগ্রহ — যেখান থেকে দ্রুত search, retrieve, update, delete করা যায়। এটি সাধারণত একটি DBMS (Database Management System) দিয়ে পরিচালিত হয়।

💡 সরল উদাহরণ: Excel file-ও এক ধরনের database — কিন্তু তাতে concurrent user, transaction, security নেই। তাই production-এ MySQL, PostgreSQL ইত্যাদি RDBMS লাগে।

DBMS কী?

DBMS = Database + Management Software। যা কাজ করে:

  • Data storage: Disk-এ structured ভাবে রাখা।
  • Data retrieval: Query language দিয়ে fetch।
  • Concurrency: অনেক user একসাথে কাজ করতে পারে।
  • Transaction: ACID guarantee।
  • Security: User-permission, encryption।
  • Backup/Recovery: Crash থেকে recover।

কেন Database দরকার?

  • Persistence: Power off হলেও data থাকে।
  • Concurrent access: হাজার user একসাথে।
  • Integrity: Constraint দিয়ে invalid data block।
  • Querying: Complex search সহজ — SQL দিয়ে।
  • Scalability: Replication, sharding দিয়ে scale।

Database-এর ধরন

১. Relational (RDBMS)

Table-based, schema-driven, SQL ব্যবহার করে। MySQL, PostgreSQL, Oracle, SQL Server।

২. NoSQL

Flexible schema। চারটি subtype:

  • Document: MongoDB, CouchDB — JSON-like document।
  • Key-Value: Redis, DynamoDB — সরল hash map।
  • Wide-column: Cassandra, HBase — column family।
  • Graph: Neo4j, ArangoDB — node + edge।

৩. Time-series

InfluxDB, TimescaleDB — IoT, monitoring metric data।

৪. Search

Elasticsearch, Solr — full-text search।

৫. NewSQL

Google Spanner, CockroachDB — RDBMS-এর reliability + NoSQL-এর scale।

OLTP vs OLAP

OLTP (Online Transaction Processing)

  • Daily operation — order, payment, login
  • অনেক ছোট transaction
  • Read + Write balanced
  • Latency-sensitive (ms)
  • Example: MySQL, PostgreSQL

OLAP (Online Analytical Processing)

  • Analytics, reporting, BI
  • Few large queries
  • Read-heavy
  • Latency-tolerant (sec/min)
  • Example: Snowflake, BigQuery, Redshift

Database-এর মূল component

  • Storage Engine: Disk-এ data কীভাবে রাখা — InnoDB, RocksDB।
  • Query Processor: SQL parse, optimize, execute।
  • Transaction Manager: ACID enforce।
  • Buffer Pool: RAM-এ frequently used data cache।
  • Write-Ahead Log (WAL): Crash recovery-র জন্য।
  • Index Manager: B-tree, hash index।

বাস্তব উদাহরণ

  • Facebook: MySQL (user data) + Cassandra (messaging) + Memcached।
  • Netflix: Cassandra (viewing history) + DynamoDB + MySQL।
  • Banking: Oracle/DB2 (strong ACID, audit)।
  • Twitter: Manhattan (custom KV) + MySQL + Redis।

সাধারণ ভুল ধারণা

  1. "NoSQL সবসময় faster": না — query pattern-এর উপর নির্ভর করে। Indexed RDBMS অনেক ক্ষেত্রে দ্রুত।
  2. "একটি DB সব সমস্যার সমাধান": Modern সিস্টেমে polyglot persistence — different data type-এ different DB।
  3. "DB scale = vertical only": Replication, sharding দিয়ে horizontal scale সম্ভব।

Best Practices

  • প্রথমে use case বুঝুন — তারপর DB choose করুন।
  • Backup ও point-in-time recovery configure করুন।
  • Monitoring (slow query log, connection pool) সেট করুন।
  • Security: encryption at rest + in transit, least privilege।
  • Schema migration tool (Flyway, Liquibase) ব্যবহার করুন।
  • Connection pool — direct connection নয়।

📌 চ্যাপ্টার সারমর্ম

  • DBMS = data + management software।
  • Relational, NoSQL (document/KV/wide-column/graph), Time-series, Search, NewSQL।
  • OLTP daily operation; OLAP analytics।
  • Polyglot persistence — multiple DB একসাথে ব্যবহার সাধারণ।
  • Use case-এর উপর DB selection নির্ভর করে।