All Products
Search
Document Center

Time Series Database:Write data

Last Updated:Mar 28, 2026

The Time Series Database (TSDB) Java SDK uses the Point class to represent a single data point. To write data, build one or more Point objects and submit them using asynchronous or synchronous mode.

Build a Point object

A Point requires a metric name, at least one tag key-value pair, a value, and a timestamp. Three timestamp formats are supported.

Data schema used in the examples below:

FieldTypeDescription
metricstringThe measurement name, e.g., test1
tagk1tagExample tag key 1
tagk2tagExample tag key 2
tagk3tagExample tag key 3
valuedoubleThe measured value
timestamplong or DatePoint in time of the measurement
Important

Every Point must include at least one tag key-value pair.

Seconds timestamp

// Convert milliseconds to seconds.
int timestamp = (int)(System.currentTimeMillis() / 1000);

Point point = Point.metric("test1")
                   .tag("tagk1", "tagv1")
                   .tag("tagk2", "tagv2")
                   .tag("tagk3", "tagv3")
                   .timestamp(timestamp).value(123.456)
                   .build();

Milliseconds timestamp with a HashMap

Use a HashMap to pass multiple tags when the number of tags is dynamic or large.

long timestamp = System.currentTimeMillis();

Map<String, String> tags = new HashMap<String, String>();
tags.put("tagk1", "tagv1");
tags.put("tagk2", "tagv2");

Point point = Point.metric("test1")
                   .tag(tags)
                   .value(timestamp, 123.456)
                   .build();

java.util.Date

Point point = Point.metric("test1")
                   .tag("tagk1", "tagv1")
                   .value(new Date(), 123.456)
                   .build();

Choose a write mode

TSDB supports two write modes:

ModeMethodBatchingBest for
Asynchronous (recommended)tsdb.put(point)AutomaticMost use cases
Synchronoustsdb.putSync(points)ManualWhen you need to inspect write results inline

Use asynchronous mode unless you have a specific reason to inspect per-batch results synchronously.

Write data asynchronously

In asynchronous mode, construct a Point and call tsdb.put(). The client automatically batches data points before submitting them.

Point point = Point.metric("test1")
                   .tag("tagk1", "tagv1")
                   .value(timestamp, Math.random())
                   .build();

tsdb.put(point);

Configure a callback interface

To inspect write results in asynchronous mode, configure a callback interface before connecting. The callback tracks successes and failures per batch.

All examples below use the single-value data model. For multi-value data points, replace the callback interface with the corresponding MultiField variant (see Callback interfaces).

final AtomicLong processedCount = new AtomicLong();

BatchPutCallback cb = new BatchPutCallback() {

    @Override
    public void response(String address, List<Point> input, Result output) {
        long total = processedCount.addAndGet(input.size());
        System.out.println("Written: " + input.size() + ", total processed: " + total);
    }

    @Override
    public void failed(String address, List<Point> input, Exception ex) {
        ex.printStackTrace();
        long total = processedCount.addAndGet(input.size());
        System.out.println("Failed: " + input.size() + ", total processed: " + total);
    }
};

TSDBConfig config = TSDBConfig
                        .address("example.hitsdb.com", 8242)
                        .listenBatchPut(cb)    // Register the callback.
                        .config();

tsdb = TSDBClientFactory.connect(config);

When each callback method is triggered:

MethodTriggered when
response()The server accepts and processes the request. The response content varies by callback type.
failed()The server rejects the request — invalid data, traffic throttling, authentication failure, or other errors.
Important

Always implement the failed() method. The default implementation is a no-op void method, so failures are silently ignored if you omit it.

Important

Do not run time-consuming operations inside callback methods. Offload heavy work to separate worker threads.

Callback interfaces

Select the callback interface that matches the write response detail you need.

Single-value data model:

Callback interfaceWrite modeEquivalent API
BatchPutCallbackSimplePOST /api/put
BatchPutSummaryCallbackStatisticalPOST /api/put?summary=true
BatchPutDetailsCallbackDetailedPOST /api/put?details=true
BatchPutIgnoreErrorsCallbackFault-tolerantPOST /api/put?ignoreErrors=true

Multi-value data model:

Callback interfaceWrite modeEquivalent API
MultiFieldbatchPutCallbackSimplePOST /api/put
MultiFieldbatchPutSummaryCallbackStatisticalPOST /api/put?summary=true
MultiFieldbatchPutDetailsCallbackDetailedPOST /api/put?details=true
MultiFieldbatchPutIgnoreErrorsCallbackFault-tolerantPOST /api/put?ignoreErrors=true

For details on response content per write mode, see Write modes and responses.

Write data synchronously

In synchronous mode, build a list of data points manually and call tsdb.putSync().

List<Point> points = new ArrayList<Point>();

for (int i = 0; i < 500; i++) {
    long timestamp = System.currentTimeMillis();
    Point point = Point.metric("test1")
                       .tag("tagk1", "tagv1")
                       .value(timestamp, Math.random())
                       .build();
    points.add(point);
}

tsdb.putSync(points);

Best practices for synchronous writes

  • Add 500–1,000 data points per batch. Fewer points per call reduces throughput; too many increases memory pressure.

  • Submit batches from multiple threads concurrently to maximize write throughput.

Synchronous response types

Configure the response type based on what your application needs to verify after each write.

Response typeCodeEquivalent APIContent
Empty objectResult result = tsdb.putSync(ps);POST /api/putNo payload
SummarySummaryResult summaryResult = tsdb.putSync(ps, SummaryResult.class);POST /api/put?summary=trueWritten count, failed count
DetailsDetailsResult detailsResult = tsdb.putSync(ps, DetailsResult.class);POST /api/put?details=trueWritten count, failed count, failure reasons