#🧱 Building Block: Elasticsearch
#Overview
Elasticsearch is a distributed, RESTful search and analytics engine based on Apache Lucene. It is designed for horizontal scalability, reliability, and real-time search capabilities.
#Key Concepts
- Index: A collection of documents that have somewhat similar characteristics.
- Document: The basic unit of information that can be indexed.
- Shard: A subset of an index. Sharding allows you to split your data across multiple nodes.
- Replica: A copy of a shard. Provides high availability and increases read throughput.
#When to Use
- Full-text Search: When you need to provide powerful search capabilities (ranking, synonyms, typos).
- Log Analytics: Storing and analyzing large volumes of log data (ELK stack).
- Faceting/Aggregations: When you need to provide real-time counts across various dimensions.
#Trade-offs
- Pros: Extremely fast search, scales horizontally, rich query DSL.
- Cons: Near real-time (not instantaneous), complex to manage at scale, high memory usage.
#Design Patterns
- CQRS: Use ES as the read-store while using a relational DB as the write-store.
- Inverted Index: The core data structure that maps terms to their locations in documents.