* Conoscenza del computer >> Computer >  >> Telefono

Architettura server di Twitter (X): JVM, microservizi, MySQL shardato, Kafka, Redis

Twitter (ora X) non gira su "un server". È una piattaforma distribuita a microservizi che gestisce ~500M tweet/giorno, timeline fanout, ricerca real-time, ads, notifiche. Ecco lo stack tecnologico core (pubblicamente noto da blog engineering, conferenze, open source).

Runtime & Linguaggi (Backend)

  • JVM ecosystem: Scala (storico, core), Java, Kotlin (adozione crescente). Tipizzazione statica, performance, ecosystem maturo.
  • Finagle (Twitter OSS): framework RPC protocol-agnostico, fault-tolerant, per servizi ad alta concorrenza. Base per comunicazione inter-servizio.
  • TwitterServer (OSS): template per servizi Finagle (healthcheck, stats, admin HTTP, tracing).

Orchestrazione & Scheduling

  • Mesos (Apache): cluster manager astratte risorse (CPU, RAM, disk) su fleet fisico/VM. Storico per Twitter.
  • Kubernetes (k8s): migrazione in corso/parziale per nuovi carichi, standard industry.
  • Aurora (Twitter OSS su Mesos): scheduler per servizi long-running, cron, ad-hoc jobs.

Data Storage (poliglotta, per use-case)

TecnologiaRuoloNote
MySQL (InnoDB)Core data: utenti, tweet, timeline, relazioniHeavy sharding (centinaia di shard), Vitess (proxy sharding) per scaling. Read replicas.
Manhattan (custom, KV store)Successore MySQL per molti workload: alta disponibilità, strong consistency, multi-dcSviluppato internamente, ispirato a DynamoDB/Bigtable.
CassandraHigh-write, time-series: direct messages, notifiche, analytics eventsWide rows, TTL, tunable consistency.
RedisCache L2, sessioni, rate limiting, pub/sub, sorted sets (timeline ranking)Cluster mode, persistence AOF/RDB.
MemcachedCache L1 (frontline) per frammenti HTML, oggetti caldiSemplice, veloce, volatile.
Hadoop / HDFS / Hive / Presto / SparkData lake, batch analytics, ML feature store, reportingPetabyte scale.
Elasticsearch / LuceneFull-text search: tweet, utenti, hashtag, log analyticsCustom analyzers, real-time indexing.

Messaging & Stream Processing

  • Kafka (Apache): backbone event streaming. Tweet firehose, engagement events, ad impressions, metriche → topic → consumer (analytics, ML, notifiche, search indexing). High throughput, replayable.
  • Kestrel / DistributedLog (legacy/custom): code di messaggi storiche, in dismissione.

Edge & Ingress

  • NGINX / Envoy: reverse proxy, load balancing L7, TLS termination, rate limiting, WAF, routing canary.
  • DNS / CDN: Akamai, Cloudflare, Fastly, AWS CloudFront per asset statici, edge compute.

Infrastruttura Cloud (ibridazione recente)

  • Storicamente: data center propri (Seattle, Atlanta, Sacramento, NY, ecc.).
  • Dal ~2018: migrazione parziale carichi su Google Cloud Platform (GCP) (BigQuery, Dataflow, GKE, Cloud Spanner valutato) e AWS (per alcune regioni/servizi). Multi-cloud per resilienza, costo, capacità GPU/TPU per ML.

Punti chiave architetturali

  1. Microservizi: centinaia di servizi indipendenti (tweet service, timeline service, user service, search service, ad service, notification service…). Deploy indipendenti, failure isolation.
  2. Fanout on write: tweet → scrivi in timeline di tutti i follower (precomputato) vs fanout on read. Mix strategie per scale.
  3. Event-driven: Kafka come sistema nervoso centrale. Tutto è evento.
  4. Custom tooling: a questa scala, build/buy → build (Manhattan, Finagle, Aurora, Observability stack, Deploy system).
  5. Observability first: metriche (Prometheus/Grafana), logging (Unified Log), tracing (Zipkin/OpenTelemetry), alerting automatizzato.

In sintesi: Twitter = JVM (Scala/Java/Kotlin) + Finagle + Mesos/k8s + MySQL shardato/Vitess + Manhattan + Cassandra + Redis + Kafka + Elasticsearch + NGINX/Envoy + data center propri + GCP/AWS. Ogni componente scelto per risolvere UN problema di scala specifico.

Telefono