Quick backend learning this week: Database Indexing What is an Index? An index helps the database find data faster without scanning the entire collection. Think of it like the index page of a book. Without index → full scan (slow) With index → direct lookup (fast) --- Single Index vs Compound Index Single Index • indexes one field Example: "email: { index: true }" Compound Index • indexes multiple fields together Example: "schema.index({ userId: 1, status: 1 })" Useful when queries filter using multiple fields. --- Good indexing isn't just optimization. It’s part of database architecture. #BackendDevelopment #MongoDB #SystemDesign #Database
Optimizing Database Performance with Indexing in MongoDB
More Relevant Posts
-
I used to think a database was just a storage layer. That assumption broke the moment I worked on a system handling continuous, high-volume writes. We started with a traditional relational setup. It worked well initially. But as traffic increased, cracks began to appear: Write latency started increasing Scaling became operationally expensive Handling spikes was unpredictable That is when I explored Apache Cassandra. What stood out immediately was its architecture. Cassandra is not built like a typical database. It is distributed by design, with no single point of failure. Every node can accept reads and writes. Scaling is not vertical, it is horizontal. This changes how you think about backend systems. Where it started making sense for me: We were dealing with: Continuous event ingestion Time-series style data A requirement for high availability In this kind of setup, Cassandra performed significantly better than a relational model. Write throughput was consistent. System reliability improved. Handling scale became predictable. But there was a learning curve. Cassandra forces you to think differently about data modeling. You do not design for relationships. You design for queries. And that shift is not trivial. Where I would not use Cassandra: Applications requiring complex joins Systems that depend on strict transactional consistency Low-scale applications where operational overhead is not justified In those cases, a relational database is still the better choice. The biggest takeaway for me: Choosing Cassandra is not a database decision. It is a system design decision. You are optimizing for: Availability Scalability High write performance And consciously trading off: Query flexibility Strong consistency If your system is write-heavy and needs to operate at scale, Cassandra becomes a serious contender. Otherwise, it can be an over-engineered choice. Curious to hear from others who have worked with Cassandra. Did it simplify your system at scale, or add complexity? #ApacheCassandra #SystemDesign #BackendEngineering #Scalability #DistributedSystems #NoSQL #DatabaseArchitecture #SoftwareEngineering #TechLeadership #EngineeringInsights
To view or add a comment, sign in
-
Choosing the right database architecture can make or break a system. 🚀 Here is a quick, no-nonsense guide to 4 essential DBMS Architecture Patterns every backend engineer should know to build scalable systems: 1️⃣ Leader-Follower (Master-Slave) Replication The Concept: One primary database (Leader) handles all the writes (inserts/updates). Multiple secondary databases (Followers) sync with the leader and handle all the reads. When to use it: Perfect for read-heavy applications (like blogs or social feeds) where a slight delay in data syncing is acceptable. 2️⃣ Sharding (Horizontal Partitioning) The Concept: Breaking a massive database table into smaller, more manageable pieces called "shards." Each shard holds a unique slice of the data and is hosted on a separate server. When to use it: When your dataset is growing so fast that it exceeds the storage or computing capacity of a single machine. 3️⃣ Vertical Partitioning The Concept: Splitting a database table by columns rather than rows. You keep frequently accessed columns in one table and move rarely used, heavy columns (like large text descriptions) to another. When to use it: When you have extremely "wide" tables and want to optimize memory and speed up specific, frequent queries. 4️⃣ CQRS (Command Query Responsibility Segregation) The Concept: A more advanced pattern that completely separates the read operations (Queries) from the write operations (Commands). They often use entirely different database technologies (e.g., PostgreSQL for writes, Elasticsearch for reads). When to use it: For highly complex systems where the read and write workloads are drastically different and need to be scaled independently. Understanding these patterns is a game-changer for designing resilient architecture. Which of these patterns do you find yourself implementing the most? Let's discuss in the comments! 👇 #BackendEngineering #SystemDesign #DatabaseArchitecture #SoftwareEngineering #Coding
To view or add a comment, sign in
-
-
🚀 𝗛𝗟𝗗 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 – 𝗗𝗮𝘆 𝟵, 𝟭𝟬 & 𝟭𝟭 | 𝗗𝗲𝘀𝗶𝗴𝗻𝗶𝗻𝗴 𝗮 𝗞𝗲𝘆–𝗩𝗮𝗹𝘂𝗲 𝗦𝘁𝗼𝗿𝗲 Continuing my High-Level Design journey, the focus for the last few days was understanding how large-scale systems build and scale Key–Value Stores. Many modern distributed databases such as DynamoDB, Redis, and Cassandra are built around this simple but powerful concept. Here’s a quick overview of the problem and design goals 👇 (Detailed notes attached) 🧩 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 A Key–Value Store is one of the simplest forms of databases but become one the complex problem when comes to large scale. It stores data in the format: 𝗞𝗲𝘆 → 𝗩𝗮𝗹𝘂𝗲 Example: 𝘂𝘀𝗲𝗿_𝟭𝟬𝟭 → {𝗻𝗮𝗺𝗲: "𝗦𝗵𝗿𝗶𝗸𝗮𝗻𝘁", 𝗰𝗶𝘁𝘆: "𝗗𝗲𝗹𝗵𝗶"} The system must quickly: • Store data using a key • Retrieve data using the same key At small scale this is easy, but the challenge begins when the system needs to handle millions of users and massive amounts of data. 🎯 𝗞𝗲𝘆 𝗗𝗲𝘀𝗶𝗴𝗻 𝗚𝗼𝗮𝗹𝘀 When designing a distributed key–value store, the system must focus on three major goals. ⚡ 𝗦𝗰𝗮𝗹𝗮𝗯𝗶𝗹𝗶𝘁𝘆 The system should handle increasing traffic and data volume without performance degradation. Achieved using 𝗣𝗮𝗿𝘁𝗶𝘁𝗶𝗼𝗻 (𝗖𝗼𝗻𝘀𝗶𝘀𝘁𝗲𝗻𝘁 𝗛𝗮𝘀𝗵𝗶𝗻𝗴) This usually requires: • Distributing data across multiple machines • Handling high read/write requests efficiently 🌐 𝗗𝗲𝗰𝗲𝗻𝘁𝗿𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻 Instead of relying on a single central database server, the system distributes data across multiple nodes. Achieved through 𝗥𝗲𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 Benefits include: • Better fault tolerance • Higher availability • No single point of failure 🔄 𝗘𝘃𝗲𝗻𝘁𝘂𝗮𝗹 𝗖𝗼𝗻𝘀𝗶𝘀𝘁𝗲𝗻𝗰𝘆 In distributed systems, all nodes may not always have the latest data instantly. Instead, the system allows temporary inconsistencies but ensures that all nodes eventually synchronize and reach the same state. This trade-off improves availability and scalability. 🎯 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 Designing a key–value store may seem simple at first, but at scale it requires solving challenges related to data distribution, fault tolerance, and consistency. 📌 I’ve attached my detailed notes explaining the architecture and concepts. Day 9, 10 & 11 completed 💪 Next topic: SQL vs No-SQL Learning Reference : Concept && Coding - By Shrayansh #SystemDesign #HLD #DistributedSystems #BackendEngineering #KeyValueStore #LearningInPublic
To view or add a comment, sign in
-
"If your team already runs Postgres and needs vector search, pgvector removes a *significant* amount of architecture complexity from the question. The key is investing the operational effort to run it well. Jacobs was right that the blog posts skip over the hard parts… but the hard parts are manageable with the right operational approach." NetApp Instaclustr's Naina Ananthaswamy with a deep dive for The New Stack on how to scale Postgres vector queries with proper indexing, tuning, and SQL filtering 💡 https://lnkd.in/ggwJ6zxR
To view or add a comment, sign in
-
𝗧𝗵𝗲 𝗗𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗗𝗲𝘀𝗶𝗴𝗻 𝗠𝗶𝘀𝘁𝗮𝗸𝗲 𝗧𝗵𝗮𝘁 𝗞𝗶𝗹𝗹𝘀 𝗦𝗰𝗮𝗹𝗮𝗯𝗶𝗹𝗶𝘁𝘆 Most systems don’t fail because of 𝘁𝗿𝗮𝗳𝗳𝗶𝗰. They fail because of 𝗱𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗱𝗲𝘀𝗶𝗴𝗻. A backend might handle millions of requests, but if the database becomes the bottleneck, the entire system slows down. Here are 𝟰 𝗰𝗼𝗺𝗺𝗼𝗻 𝗺𝗶𝘀𝘁𝗮𝗸𝗲𝘀 𝘁𝗵𝗮𝘁 𝗾𝘂𝗶𝗲𝘁𝗹𝘆 𝗸𝗶𝗹𝗹 𝘀𝗰𝗮𝗹𝗮𝗯𝗶𝗹𝗶𝘁𝘆: 𝟭. 𝗦𝗶𝗻𝗴𝗹𝗲 𝗗𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗕𝗼𝘁𝘁𝗹𝗲𝗻𝗲𝗰𝗸 Everything reads and writes to one DB instance. Eventually CPU, connections, or I/O become the limit. 𝟮. 𝗟𝗮𝗰𝗸 𝗼𝗳 𝗜𝗻𝗱𝗲𝘅𝗶𝗻𝗴 A missing index can turn a 20ms query into a 2-second query. 𝟯. 𝗣𝗼𝗼𝗿 𝗦𝗰𝗵𝗲𝗺𝗮 𝗗𝗲𝘀𝗶𝗴𝗻 Badly structured relations or heavy joins create slow queries as data grows. 𝟰. 𝗠𝗶𝘀𝘀𝗶𝗻𝗴 𝗖𝗮𝗰𝗵𝗶𝗻𝗴 𝗟𝗮𝘆𝗲𝗿 Fetching frequently accessed data directly from the DB increases load unnecessarily. ⚙️ 𝗛𝗼𝘄 𝘀𝗰𝗮𝗹𝗮𝗯𝗹𝗲 𝘀𝘆𝘀𝘁𝗲𝗺𝘀 𝘀𝗼𝗹𝘃𝗲 𝘁𝗵𝗶𝘀 Instead of relying on a single database, they introduce patterns like: • Read Replicas → distribute read traffic • Sharding → split data across multiple databases • Caching (Redis/Memcached) → reduce DB queries • CQRS → separate read and write workloads The goal is simple: 𝗥𝗲𝗺𝗼𝘃𝗲 𝘁𝗵𝗲 𝗱𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗮𝘀 𝘁𝗵𝗲 𝘀𝘆𝘀𝘁𝗲𝗺’𝘀 𝗯𝗶𝗴𝗴𝗲𝘀𝘁 𝗯𝗼𝘁𝘁𝗹𝗲𝗻𝗲𝗰𝗸. 💬 𝗖𝘂𝗿𝗶𝗼𝘂𝘀 𝘁𝗼 𝗵𝗲𝗮𝗿 𝗳𝗿𝗼𝗺 𝗼𝘁𝗵𝗲𝗿 𝗲𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝘀: 𝗪𝗵𝗮𝘁 𝘄𝗮𝘀 𝘁𝗵𝗲 𝗯𝗶𝗴𝗴𝗲𝘀𝘁 𝗱𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗯𝗼𝘁𝘁𝗹𝗲𝗻𝗲𝗰𝗸 𝘆𝗼𝘂 𝗲𝗻𝗰𝗼𝘂𝗻𝘁𝗲𝗿𝗲𝗱 𝗶𝗻 𝗽𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻? #SystemDesign #BackendEngineering #Databases #SoftwareArchitecture #ScalableSystems
To view or add a comment, sign in
-
Building a Production RAG System with .NET and PostgreSQL AI systems are not just about models. They are about how you retrieve and use data. PostgreSQL with pgvector allows you to build scalable RAG systems without introducing a separate vector database. Core architecture: Ingestion layer Convert documents into embeddings and store them in PostgreSQL Storage layer Store content, metadata, and embeddings together Retrieval layer Use vector similarity search to find relevant content Query layer Combine SQL filters with vector search Application layer Send retrieved context to the language model for answer generation Example query: SELECT content FROM documents WHERE tenant_id = 10 ORDER BY embedding <-> query_embedding LIMIT 5; Best practices: Filter before vector search Use indexes like HNSW or IVFFlat Chunk documents properly Limit the amount of context sent to the model Use caching for repeated queries Scaling strategies: Partition data by tenant or time Use read replicas for heavy query workloads Batch embedding generation Tune index parameters for performance Multi-tenant systems: Always enforce tenant isolation Filter data before retrieval Ensure security boundaries are maintained Final thought: The strength of a RAG system is not the model. It is the quality of retrieval. Good retrieval leads to accurate generation.
To view or add a comment, sign in
-
-
💡 Do relational databases only support vertical scaling? This is something I recently revisited while learning about database architecture. Many people say relational databases scale only vertically — meaning we increase the power of a single machine (more CPU, RAM, storage). This is partially true, but not the full picture. Relational databases like MySQL and PostgreSQL can also achieve horizontal scaling using techniques such as: 🔹 Replication A primary database handles write operations, while multiple replica databases handle read queries. This improves read performance and reduces load on the primary database. 🔹 Sharding The data is split across multiple databases (called shards). Each database stores a portion of the data, allowing the system to handle very large datasets and higher traffic. In short: • Vertical Scaling → Bigger machine • Horizontal Scaling → More machines using replication or sharding Understanding these concepts is an important step toward designing scalable systems. Small learning today, but an important building block in understanding how large-scale applications manage their databases. 🚀 Monal S. Krish Naik Mayank Aggarwal Sourangshu Pal KRISHAI Technologies Private Limited #SystemDesign #Database #BackendDevelopment #DistributedSystems #SoftwareEngineering #SQL #LearningInPublic
To view or add a comment, sign in
-
-
Hi! Mastering Vector Database Partitioning for High Performance Large Scale RAG Systems Retrieval‑Augmented Generation (RAG) has reshaped the way we build large‑language‑model (LLM) powered applications. By coupling a generative model with a fast, similarity‑based retrieval layer, RAG enables grounded, up‑to‑date, and domain‑specific responses. At the heart of that retrieval layer lies a vector database—a specialized system that stores high‑dimensional embeddings and serves nearest‑neighbor (k‑NN) queries at scale. When a RAG system grows beyond a few million vectors, naïve storage and query execution quickly become bottlenecks. Latency spikes, hardware costs rise, and operational complexity explodes. Partitioning—splitting the vector space across multiple logical or physical shards—offers a proven path to high performance, horizontal scalability, and cost‑effective resource utilization. This article provides a deep dive into vector database partitioning for large‑scale RAG systems. We’ll explore the theory behind partitioning, practical strategies, concrete code examples for leading open‑source vector stores, and real‑world operational guidance. By the end, you’ll have a reproducible blueprint you can adapt to any production RAG pipeline. Read the full guide: https://lnkd.in/diFjd2aW #vectordatabases #RAG #partitioning #scalability #performance
To view or add a comment, sign in
-
The "Invisible" Table Scans 👻 Headline: Your Index-Only Scan isn't actually an Index-Only Scan. 🛑 You’ve built a massive index. You’re only selecting the columns in that index. You run EXPLAIN and you see "Index Only Scan." You celebrate. 🥳 Then why is the query still hitting the disk like a freight train? 🚂 The "Damn!" Moment: PostgreSQL is a "trust but verify" engine. Even if all the data is in the index, Postgres doesn't know if that data is visible to your current transaction. It might be a dead tuple from a previous update or an uncommitted change from another user. To check this, Postgres has to look at the Visibility Map. The Problem: If your table hasn't been VACUUMed recently, the Visibility Map is "dirty." The Result: Even if the query plan says "Index Only Scan," the database is forced to "Fetch the Heap" (hit the actual table) to verify visibility. You’re doing a table scan in disguise. 📉 The "Surgical Engineering" Hack: The Visibility Audit 💎 At LatentFix, we’ve seen high-throughput systems slow down purely because of "Visibility Debt." Here is how you fix it: The Check: Check the Heap Fetches in your EXPLAIN (ANALYZE, BUFFERS) output. If it’s > 0, your Index-Only Scan is failing you. The Fix: Tune your autovacuum settings for that specific table. You need frequent, fast vacuums to keep the Visibility Map "clean." The Payoff: Zero heap fetches. Data served purely from the index. Total disk I/O reduction. 🏎️ Stop guessing why your indexes are slow. Start auditing your visibility. 🛠️ #PostgreSQL #DatabaseOptimization #BackendEngineering #CodingHacks #LatentFix #SystemDesign #SoftwareArchitecture #CTOLife #PerformanceMatters #StartupScaling
To view or add a comment, sign in
-
-
You don't need a vector database. You need a vector column. I've shipped semantic search in production over 10,000+ profiles using pgvector on vanilla Postgres. No Pinecone. No Weaviate. No new infrastructure at all. One extension, one migration, one index. The "vector database" category got created because VCs funded standalone products for it. That made sense in 2023 when Postgres couldn't handle embeddings well. It doesn't make sense now. pgvectorscale, the optimised extension for Postgres, just benchmarked 471 queries per second at 99% recall on 50 million vectors. Qdrant, one of the best purpose-built vector databases, hit 41 QPS on the same test. That's an order of magnitude difference, and it runs on the database you already have. For the vast majority of AI search and matching products at seed stage, a dedicated vector database is unnecessary complexity. You're adding a new service to deploy, a new failure point to monitor, and a data sync problem to maintain. For what? Your corpus is 50,000 rows, not 500 million. The question is not "which vector database should I use." The question is "do I need one at all." For most early-stage products, the answer is no. Add the extension. Store the embeddings alongside your existing data. Query them with your existing ORM. Ship it. The infrastructure decision that matters is upstream: how you summarise before you embed, and how you structure the query pipeline. That's where search quality lives. The storage layer is a solved problem.
To view or add a comment, sign in
Example from a real system: indexing { eventId, createdAt } helped us fetch event tickets much faster during peak traffic.