Skip to content

Understanding the SDK API

This guide explains the design philosophy behind the Developer SDK and how to use its patterns effectively.

Why fluent design?

The Developer SDK uses a fluent interface pattern—methods return the object itself, enabling method chaining that reads like natural language.

Classic client vs. SDK client

import java.time.Duration;
import com.aerospike.client.sdk.DataSet;
// Classic Client - verbose, configuration-heavy
WritePolicy policy = new WritePolicy();
policy.sendKey = true;
policy.expiration = 3600;
Key key = new Key("test", "users", "user-1");
Bin bin1 = new Bin("name", "Alice");
Bin bin2 = new Bin("age", 28);
client.put(policy, key, bin1, bin2);
// Developer SDK - chainable, readable
DataSet users = DataSet.of("test", "users");
session.insert(users)
.bins("name", "age")
.id("user-1").values("Alice", 28)
.sendKey()
.expireRecordAfter(Duration.ofSeconds(3600))
.execute();

Method chaining philosophy

Fluent interfaces follow these principles:

  1. Discoverability: IDE autocomplete guides you through available options
  2. Readability: Code reads like a sentence describing what it does
  3. Immutability: Each chain step returns a new builder (no mutation)
  4. Terminal Operations: Chains end with an action (execute(), then stream iteration for queries)

Builder pattern integration

The Developer SDK uses builders for complex configuration:

import com.aerospike.client.sdk.Cluster;
import com.aerospike.client.sdk.ClusterDefinition;
import com.aerospike.client.sdk.Host;
// Cluster connection (multiple seed hosts)
Cluster cluster = new ClusterDefinition(
new Host("localhost", 3000),
new Host("localhost", 3001)
).connect();
// Session from cluster
Session session = cluster.createSession(Behavior.DEFAULT);

When fluent shines

The fluent pattern is most valuable when:

  • Operations have many optional parameters
  • Configuration is complex but has sensible defaults
  • Code readability is important for maintenance
  • IDE support can guide developers

Next steps

Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?