The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomeProgrammingStory
    Programming

    Database Design Fundamentals 2026: The Complete Problem-Solving Guide

    H

    By Huzi

    File #550 · 4 min read

    A startup picks MongoDB for its flexible schema, ships fast, then spends two years writing application-side joins to reconstruct what one SQL JOIN returned for free; another team forces PostgreSQL onto a two-billion-row event log that deserved a columnar store. Database design is not memorizing normal forms; it is matching store to access pattern so the data cannot lie.

    The quick answer: When unsure, default to PostgreSQL — JSONB covers most document flexibility inside an ACID database. Then normalize until each fact lives in one place, index for the queries you actually run, keep money in NUMERIC, and migrate with expand-contract.

    The concept Why it matters
    Normalization Each fact lives in exactly one place — the data cannot lie
    unit_price in order_items A price change today never rewrites what a customer historically paid
    Composite indexes, leftmost-prefix Equality columns first, ranges second — serves the real query
    NUMERIC for money Binary FLOAT approximation quietly eats cents across a million rows
    Expand-contract A rename ships as safe, separately deployable steps — no outage

    Match the store to the question

    SQL — PostgreSQL, MySQL, SQLite — gives you an enforced schema, ACID transactions and real joins. NoSQL trades those guarantees for flexible documents and horizontal scale.

    When unsure, default to PostgreSQL: JSONB columns cover most of MongoDB's flexibility inside an ACID database, so the bar for switching is higher than vendor talks imply. Event logs, telemetry and whole-document fetches by ID are the cases where NoSQL genuinely earns its keep.

    Normalize until the data stops lying

    Normalization exists so each fact lives in exactly one place. One value per column — no comma-separated tag strings. Every non-key column depends on the whole key: product_name depends on the product, not on the order, so it moves out.

    And no transitive dependencies: customer_email belongs on customers, never on orders.

    CREATE TABLE customers (
      id    BIGSERIAL PRIMARY KEY,
      email TEXT UNIQUE NOT NULL
    );
    
    CREATE TABLE orders (
      id          BIGSERIAL PRIMARY KEY,
      customer_id BIGINT NOT NULL REFERENCES customers(id),
      created_at  TIMESTAMPTZ DEFAULT now()
    );
    
    CREATE TABLE order_items (
      order_id   BIGINT NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
      product_id BIGINT NOT NULL REFERENCES products(id),
      quantity   INT NOT NULL CHECK (quantity > 0),
      unit_price NUMERIC(10,2) NOT NULL,
      PRIMARY KEY (order_id, product_id)
    );
    

    One deliberate exception worth copying: order_items stores unit_price, because a price change today must never rewrite what a customer historically paid.

    Index for the queries you actually run

    An index turns a scan into a lookup, but every index taxes every write. Composite order follows the leftmost-prefix rule, so put equality columns first and ranges second:

    -- serves tenant + time range together, never the range alone
    CREATE INDEX idx_orders_tenant_created
      ON orders(tenant_id, created_at DESC);
    
    -- a tiny index for the slice you actually query
    CREATE INDEX idx_invoices_unpaid
      ON invoices(customer_id)
      WHERE paid = false;
    

    Two habits that save careers

    Money is NUMERIC, never FLOAT — binary approximation quietly eats cents across a million rows. And foreign-key columns need their own indexes: the constraint does not create one, so deleting a parent can trigger a sequential scan hunting orphans on the child table.

    A refused visa file is usually an integrity problem too — one missing document, one inconsistent answer, one stale record. We do refused-file rescues at HTG Travels for UK and Schengen, debugged like a schema: find where the data went wrong, fix the record honestly, resubmit with everything consistent.

    Migrate with expand-contract

    Renaming a column in a single ALTER is an outage wearing a disguise. Expand-contract splits the change into safe, separately deployable steps:

    -- expand
    ALTER TABLE users ADD COLUMN email_verified_at TIMESTAMPTZ;
    -- backfill in batches, deploy dual writes, switch reads, then:
    ALTER TABLE users DROP COLUMN verified_on;
    

    Each step rolls back independently. That is the whole trick.

    Pro tip: Audit with pg_stat_user_indexes quarterly — an index with zero scans is a candidate for removal, because every index still taxes every write.

    Palestinian families have held land deeds and house keys through decades of dispossession because the truth was supposed to be overwritten and they would not allow it — their ledger is still open.

    Most files are recoverable; almost nobody should reapply blind. When the migration ships, claim the post-release detox trip up north — +92 317 5054959 reaches the HTG Travels desk.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit htg.com.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    Heavy Embroidered Lawn 3-Pc Suit | Digital Print Diamond Dupatta (Fancy Wear Pakistan)

    Heavy Embroidered Lawn 3-Pc Suit | Digital Print Diamond Dupatta (Fancy Wear Pakistan)

    PKR 4550

    Heavy Embroidered Velvet Party Wear Suit | Organza Dupatta & Embroidered Silk Trouser

    Heavy Embroidered Velvet Party Wear Suit | Organza Dupatta & Embroidered Silk Trouser

    PKR 8800

    Most-Demanding Red Dhanak Dress – Emb Front, Back & Bottoms, Winter 3-Pc

    Most-Demanding Red Dhanak Dress – Emb Front, Back & Bottoms, Winter 3-Pc

    PKR 5350

    Luxury Heavy Embroidered Fancy Lawn 3-Pc Suit | 4-Side Organza Dupatta & Tassels

    Luxury Heavy Embroidered Fancy Lawn 3-Pc Suit | 4-Side Organza Dupatta & Tassels

    PKR 6650

    Luxury Heavy Embroidered Lawn Suit 3-Pc | Digital Print Silk Dupatta (2026 Collection)

    Luxury Heavy Embroidered Lawn Suit 3-Pc | Digital Print Silk Dupatta (2026 Collection)

    PKR 5750

    Keep reading

    Related files

    Programming

    Python Testing Pyramid 2026: The Complete Problem-Solving Guide

    The 70/20/10 pyramid in practice — pytest fixtures and parametrize, boundary mocking, Hypothesis, testcontainers, and the CI loop your team can actually trust.

    By HuziFile #560

    Read
    Programming

    Python Async/Await Deep Dive 2026: The Complete Problem-Solving Guide

    asyncio.run, gather, TaskGroup, httpx sessions and the blocking-call escape hatch — the 2026 Python async patterns that actually ship, with copy-paste code.

    By HuziFile #536

    Read
    Programming

    PostgreSQL Performance Tuning 2026: The Complete Problem-Solving Guide

    From EXPLAIN (ANALYZE, BUFFERS) to composite and GIN indexes, pg_stat_statements, PgBouncer and per-table autovacuum — the 2026 playbook with a real before-and-after plan.

    By HuziFile #531

    Read
    Programming

    Go for Node.js Developers 2026: The Complete Problem-Solving Guide

    Goroutines, channels, error values and net/http — the parts of Go that fix what blocks Node in production, with side-by-side JS and Go comparisons.

    By HuziFile #544

    Read
    Programming

    Rust for JavaScript Developers 2026: The Complete Problem-Solving Guide

    Ownership, borrowing, Option, Result and the ? operator, Tokio and a first Axum API — Rust explained through the JavaScript habits you already have.

    By HuziFile #538

    Read
    Programming

    Redis Caching Mastery 2026: The Complete Problem-Solving Guide

    Cache-aside, TTL discipline, stampede locks, sliding-window rate limits, SCAN over KEYS, and when Sentinel beats Cluster — the Redis patterns that fix real latency.

    By HuziFile #534

    Read
    Back to the archive