Jerónimo López
Jerónimo López
7 min read

When I first started working with Apache Parquet, native support in Java was essentially limited to local files and Hadoop HDFS. S3 support was available through the hadoop-aws module, but using it meant bringing the Hadoop client into the project. That added a large set of transitive dependencies, increased the attack surface, and introduced cumbersome configuration.

The usual alternatives, downloading S3 objects to a temporary local disk before reading them, or writing locally before uploading them, introduce unnecessary I/O overhead and latency.

Even though Parquet was born in the Hadoop ecosystem, tied to MapReduce and Spark, the file format itself is independent of Hadoop infrastructure. That means there is no fundamental reason we should need to route everything through temporary filesystems or heavyweight libraries just to read or write data from S3.

To fill that gap, I implemented a library that extends parquet-java and enables direct interaction with any service implementing the S3 protocol. Thanks to this work, Carpet and other libraries built on top of parquet-java can now work with S3 without going through Hadoop.

The new carpet-s3 module acts as a bridge between Parquet’s input/output abstractions and the AWS SDK for Java, completely removing the need for Hadoop dependencies.

Adding S3 support

Although it was developed inside the Carpet project, the carpet-s3 module is published as an independent artifact and does not depend on the main carpet-record library. Since it implements the InputFile and OutputFile abstractions from parquet-java, it can be used with any library built on top of parquet-java (Parquet Avro or Parquet Protobuf), whether or not you are using Carpet.

To start using it, simply add the carpet-s3 module alongside your existing Parquet or Carpet configuration.

With Maven:

<dependency>
    <groupId>com.jerolba</groupId>
    <artifactId>carpet-record</artifactId>
    <version>0.8.2</version>
</dependency>
<dependency>
    <groupId>com.jerolba</groupId>
    <artifactId>carpet-s3</artifactId>
    <version>0.8.2</version>
</dependency>

Or with Gradle:

implementation 'com.jerolba:carpet-record:0.8.2'
implementation 'com.jerolba:carpet-s3:0.8.2'

The module is built on top of the AWS SDK for Java v2. By default, it resolves credentials and regions automatically using the standard AWS credential provider chain. That means applications running with IAM roles, environment variables, or local AWS profiles work without extra setup.

Reading a Parquet file from S3

Reading Parquet files directly from S3 only requires using the new InputFile implementation: S3InputFile

record Event(long id, String name, long timestamp) { }

InputFile inputFile = S3InputFile.of("s3://my-bucket/events/data.parquet");
List<Event> events = new CarpetReader<>(inputFile, Event.class).toList();

S3InputFile parses the s3:// URI to identify the bucket and object key, then uses the AWS SDK to issue the low-level HTTP range requests needed to download only the required bytes.

Transfer optimization with projections

Because Parquet is a columnar format, you only pay for the data you read. When a file is mapped to a record containing only a subset of the available fields, Carpet requests only the relevant column chunks for those fields, saving I/O operations and transfer time:

record EventName(String name) { }

List<String> names = new CarpetReader<>(inputFile, EventName.class)
    .stream()
    .map(EventName::name)
    .toList();

In this example, S3InputFile fetches only the byte ranges corresponding to the name column. Unread columns are never downloaded, significantly reducing bandwidth usage and I/O latency when querying large datasets in S3.

Writing a Parquet file to S3

Writing Parquet files directly to S3 follows the same pattern. You simply pass an instance of S3OutputFile to the writer:

OutputFile outputFile = S3OutputFile.of("s3://my-bucket/events/output.parquet");

try (CarpetWriter<Event> writer = new CarpetWriter<>(outputFile, Event.class)) {
    writer.write(events);
}

Under the hood, S3OutputFile streams the data generated by the Parquet library and sends it to S3 using parallel multipart uploads, without needing a temporary local file.

The resulting artifact is a standard Parquet file, fully compatible with other tools and engines in the ecosystem, such as Apache Spark, DuckDB, or AWS Athena.

Optimizations

Amazon S3 is an object store, not a traditional filesystem. Data is retrieved over HTTP, and treating a remote S3 object as if it were a local random-access file introduces inefficiencies.

The Parquet architecture reads the file footer first (located at the end of the file) to inspect the schema, row group locations, and column statistics before reading any real data. To read the footer, Parquet makes multiple requests.

To minimize latency and maximize bandwidth usage, Carpet S3 implements several optimizations for both reading and writing.

Reading

S3InputFile improves read performance by reducing the number of requests and parallelizing downloads:

  • Footer caching: It issues an initial HTTP ranged request to eagerly fetch the last 8 MiB of the file. In most cases, that single request retrieves the complete footer and metadata, avoiding multiple network round trips before real data processing begins. If the file is small, it is loaded into memory in one go. Footer caching

  • Parallel ranged reads: Once the footer is parsed and analyzed, and the relevant columns and data blocks for each row group are identified, the load of each row group is performed in parallel to maximize available bandwidth. Parallel ranged reads

  • Speculative prefetching: While the CPU decodes and processes the current row group’s data, S3InputFile asynchronously fetches the next data ranges. The blocks to download are inferred from the columns referenced in the previous row group. Overlapping I/O and CPU work reduces the overall processing time. Speculative prefetching

Writing

Writing to S3 presents a different challenge. Parquet writes files sequentially by row group, but S3 allows uploads to happen in parallel and asynchronously.

S3OutputFile takes advantage of that by using S3 multipart uploads: once a row group is encoded, its data is kept in memory; while the next row group is being encoded, the previous one is uploaded in parallel using multiple multipart requests.

cache-footer

All of these internal optimizations, footer caching, parallel reads, multipart streaming, and so on, work together to keep data movement efficient and transparent to the application.

Customizing Carpet S3

Carpet S3 adopts default configurations, but it is also configurable. You can customize the S3 client used by the library, as well as concurrency and memory-related options.

I/O settings and concurrency

Using the available builder, you can control how transfers are performed and how much parallelism is used when making requests:

  • Multipart request size: Adjust the number of bytes sent to S3 per request.
  • Concurrency limits: Set the maximum number of parallel HTTP GET and PUT requests.
  • Custom executor: Provide a dedicated ExecutorService for asynchronous I/O tasks and background prefetching, ensuring that Carpet operations run within thread pools managed by you.
S3OutputFile outputFile = S3OutputFile.builder("s3://my-bucket/events/data.parquet")
    .partSize(30 * 1024 * 1024) // 30 MiB
    .concurrency(4)
    .build();

S3InputFile inputFile = S3InputFile.builder("s3://my-bucket/events/data.parquet")
    .prefetch(false)
    .executor(myExecutor)
    .build();

S3 client

For most applications deployed in S3 environments, the AWS SDK’s default auto-configuration is enough, so you do not need to configure anything in code.

Internally, the AWS SDK resolves credentials, regions, and endpoint settings automatically through the default provider chain by checking environment variables, system properties, local profiles, container metadata, and IAM execution roles.

The SDK also works with any S3-compatible object storage solution, including LocalStack for local testing, Cloudflare R2, MinIO, or Ceph.

If your application requires different S3 client settings than the defaults, such as a specific region or endpoint, custom timeouts, or a custom retry policy, you can provide your own preconfigured S3Client.

To override the default configuration or point to an alternative S3 provider, configure the S3Client with a custom endpoint and credentials:

S3Client client = S3Client.builder()
    .endpointOverride(URI.create("https://<account-id>.r2.cloudflarestorage.com"))
    .credentialsProvider(StaticCredentialsProvider.create(
        AwsBasicCredentials.create("access-key", "secret-key")
    ))
    .region(Region.US_EAST_1)
    .build();

OutputFile outputFile = S3OutputFile.builder("s3://my-bucket/events/output.parquet")
    .withS3Client(client)
    .build();

Seamless local development fallback

A particularly useful feature for simplifying development is the ability to fallback transparently to local paths when an S3 service is not available. S3InputFile and S3OutputFile inspect the scheme of the configured URI: if the path does not start with s3:// and points to a local file or directory, the library delegates the operation to the local file implementation.

This configuration uses the local filesystem:

void doSomething(String path) {
    InputFile inputFile = S3InputFile.of(path);
    ..
    OutputFile outputFile = S3OutputFile.of(path);
    ..
}

doSomething("/tmp/events.parquet");

This removes the need to add if/else branches based on file path or to wrap filesystem access in your business logic. You can write your data pipelines using S3InputFile and S3OutputFile everywhere, run fast unit and integration tests with local files or temporary directories, and deploy the same code in production against real S3 storage.

Conclusion

Storing Parquet files in S3 is a standard practice in modern data pipelines. However, interacting with them from Java applications has historically forced a tradeoff: either accept all the heavy dependencies required by Hadoop and its S3 integration, or deal with inefficient round trips to local disk.

carpet-s3 offers a lightweight, Hadoop-free alternative. By integrating directly into Parquet’s low-level I/O layer, it provides footer caching, parallel range reads, asynchronous multipart uploads, and local file fallback. All of this is exposed through a clean, intuitive API. Since it implements the interfaces of parquet-java, it can be adopted by any Java application using parquet-java, regardless of whether it also uses Carpet.

Most importantly, the programming model remains clean and consistent: switching from a local filesystem to cloud storage is as simple as replacing a path with an s3:// URI, without changing data models, schemas, or processing logic.

Next Steps

To explore advanced configurations, including fine-tuning upload/download buffers, custom thread pool execution, system properties, and pre-download modes, check out the Carpet S3 Documentation.

The full source code and issue tracker are hosted on GitHub, and artifacts are available directly via Maven Central.