Sobes.tech
Middle+

How to design a storage and search system for 10,000 Telegram channels with 300,000 posts per day with latency less than 2 seconds?

sobes.tech AI

Answer from AI

To store and search through 10,000 Telegram channels with 300,000 posts per day and a delay of less than 2 seconds, the following architecture can be used:

  1. Data Storage:

    • Use a distributed storage, such as Apache Cassandra or ClickHouse, which scale well and support fast input of large volumes of data.
  2. Indexing and Search:

    • For full-text search — Elasticsearch or OpenSearch, which provide fast text search.
    • Indexing should occur in near real-time to minimize delay.
  3. Data Processing:

    • Use stream processing (Kafka + Apache Flink/Storm) for collecting and processing posts in real-time.
  4. Caching:

    • Use Redis or Memcached for frequently requested data.
  5. Query Optimization:

    • Partition data by channels and time (sharding) to reduce the volume of data for search.
  6. Infrastructure:

    • Horizontal scaling of clusters to ensure necessary performance.

Example of a simplified Elasticsearch query schema for keyword search:

GET /posts/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "text": "keyword" }},
        { "term": { "channel_id": "12345" }}
      ]
    }
  },
  "size": 50
}

This approach will enable fast search with low latency even with a large volume of data.