Architecture Intermediate
Read Replicas — scaling čtení¶
Read ReplicasDatabaseScaling 3 min read
Škálování database pomocí read replik. Master-slave replikace a routing.
Principle¶
80-90% operací je čtení. Read replicas distribuují čtecí zátěž na kopie master DB.
Application Routing¶
const master = new Pool({ host: 'master-db' });
const replica = new Pool({ host: 'replica-db' });
class Database {
async query(sql, params, opts = {}) {
const pool = opts.readOnly ? replica : master;
return pool.query(sql, params);
}
}
await db.query('INSERT INTO orders ...', [data]); // → master
await db.query('SELECT * FROM orders', [], { readOnly: true }); // → replica
Summary¶
Nejsimpler způsob scaling čtení. Pozor na replication lag — critical čtení po zápisu z masteru.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.