Java is the substrate most distributed data systems are built on. Spark, Flink, Kafka, Beam, Hadoop, Cassandra, Elasticsearch, and Trino all run on the JVM, and their internals - partitioning, serialization, memory management, garbage collection - are Java problems whether or not you write Java. Even when you script jobs in PySpark or use Kafka from Python, the engine executing the work is a JVM process you have to tune and debug.

Why the JVM dominates data infrastructure

The JVM gives long-running services portable bytecode, a mature threading model, and just-in-time compilation that makes hot loops fast after warmup. That combination fits engines that hold large heaps for hours and shuffle gigabytes between nodes. The cost is the heap itself: a Spark executor with a 16 GB heap can spend whole seconds in a stop-the-world G1 collection, which is why off-heap memory (Spark's Tungsten, Kafka's page cache, Flink's managed memory) exists to keep large buffers out of the garbage collector's reach.

SystemWritten inWhat you tune in the JVM
Apache SparkScala/JavaExecutor heap, off-heap, GC, serializer (Kryo)
Apache FlinkJavaManaged memory, network buffers, RocksDB state backend
Apache KafkaScala/Java (Kraft: Java)Heap (modest), page cache, GC pauses on broker
Apache BeamJava SDK first-classRunner-dependent (Dataflow, Flink, Spark)
Trino / PrestoJavaQuery memory pools, JIT, GC

A Kafka producer in plain Java

The Java client is the reference implementation; other languages wrap librdkafka or reimplement the protocol. Producing here means setting serializers, an idempotence flag for exactly-once semantics within a session, and an acks level that trades durability against latency.

Properties props = new Properties();
props.put("bootstrap.servers", "broker1:9092,broker2:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("acks", "all");            // wait for all in-sync replicas
props.put("enable.idempotence", true);

try (KafkaProducer<String, String> producer = new KafkaProducer<>(props)) {
    producer.send(new ProducerRecord<>("events", "user-42", "{\"action\":\"click\"}"));
    producer.flush();
}

GC and serialization are the real cost centers

Most JVM data jobs fail or slow down for two reasons: garbage-collection pauses and slow serialization. For batch and streaming engines on large heaps, G1GC is the default; for very large heaps (32 GB+) ZGC or Shenandoah cut pause times to single-digit milliseconds at some throughput cost. On the serialization side, Spark's default Java serializer is slow and verbose - switching to Kryo (spark.serializer=org.apache.spark.serializer.KryoSerializer) and registering your classes routinely halves shuffle size. Watch jstat -gcutil <pid> 1000 or the GC logs before reaching for more memory; an undersized young generation causes far more pauses than a too-small heap.

Frequently asked questions

Do I need to know Java to use Spark or Flink? To write jobs, no - PySpark and the SQL APIs cover most pipelines. To debug a stuck executor, read a heap dump, or fix a serialization error, yes: the stack traces and tuning knobs are JVM ones, so reading Java and understanding the heap pays off quickly.

Java or Scala for new Spark/Flink code? Both compile to the same bytecode and call the same APIs. Scala is more concise for Spark's functional transformations and is what Spark itself is written in; Java is fine and often preferred by teams without Scala experience. Flink's Java API is fully first-class.

Which garbage collector should a Spark executor use? G1GC for heaps up to ~32 GB (the default on modern JDKs). For larger heaps where pause time matters, test ZGC. Always sample GC behavior under real load rather than copying someone else's flags.

What JDK version should data tooling run on? A long-term-support release - JDK 17 or 21 - that your engine officially supports. Recent Spark and Flink versions target 17+; running on an unsupported JDK leads to obscure reflection and module-access errors.