Sobes.tech
Junior — Middle

What approaches do you use for processing and transmitting large volumes of data (about 20 million records) from a database to a messaging system?

sobes.tech AI

Answer from AI

When processing and transmitting large volumes of data (around 20 million records) from a database to a messaging system, it is important to consider performance and memory load.

Main approaches:

  • Batch processing — read data in portions (for example, 1000 or 10000 records) to avoid loading the entire dataset into memory at once.

  • Streaming processing — use cursors or streams from the database to read data as needed.

  • Asynchronous message sending — after receiving each batch of data, send it to the message queue without waiting for the full load.

  • Parallelism — if the architecture allows, process multiple batches in parallel.

  • Compression and serialization — use efficient formats (e.g., Avro, Protobuf) to reduce message size.

Example in Java using JDBC and sending to a queue (pseudo-code):

int batchSize = 10000;
try (Connection conn = dataSource.getConnection();
     PreparedStatement ps = conn.prepareStatement("SELECT * FROM big_table",
         ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
    ps.setFetchSize(batchSize);
    try (ResultSet rs = ps.executeQuery()) {
        List<Record> batch = new ArrayList<>();
        while (rs.next()) {
            batch.add(mapRowToRecord(rs));
            if (batch.size() == batchSize) {
                messageQueue.send(batch); // send to messaging system
                batch.clear();
            }
        }
        if (!batch.isEmpty()) {
            messageQueue.send(batch);
        }
    }
}

This approach allows efficient processing of large data volumes without memory overload.

What approaches do you use for processing and… - sobes.tech