All Products
Search
Document Center

HTTPDNS:Best practices

Last Updated:Jun 17, 2026

HTTPDNS resolves domain names over HTTP APIs. When official SDKs cannot be directly integrated, developers can use custom access methods. This guide covers availability, performance, resolution quality, and security recommendations to help you optimize HTTP API usage.

1. Availability optimization

Scenario: Specific HTTPDNS service nodes are unavailable

Background information

In extreme cases, such as natural disasters, ISP blockages, and network failures, a single HTTPDNS service entry point may become unavailable, which affects domain name resolution.

Solutions

  1. Startup IP address failover

    • Embed multiple startup IP addresses or domain names in your application to maintain continuous connectivity with HTTPDNS.

    • If the request fails, the next startup IP address is used automatically.

  2. Dynamic update of the service IP address list

    The following flowchart shows how to obtain a service IP address by sending a request to a startup IP address.

image

For more information, see Scheduling Service Interface.

Note

We recommend that you update and save the service IP address list in the following scenarios:

  • (Recommended) Update the service IP address list when a cold start is initiated.

  • (Recommended) Update the service IP address list when you switch the network environment.

  • (Recommended) Update the service IP address list at least once every 8 hours

  • When the service IP address list cannot be resolved after retries, update the list.

  1. Failover policy

    HTTPDNS uses an IP rotation mechanism. If an IP address is unreachable, the system rotates to the next IP address, ensuring that HTTPDNS remains available even if one service IP address fails. When a resolution request is sent, the system retrieves an available service IP address from the global list. If the resolution succeeds, the SDK continues using this IP address throughout its lifecycle. If the resolution fails, the system switches to the next IP address in the list. If the retry also fails, the system returns null and attempts another service IP address.

image
Important
  • The cursor is global. We recommend that you store the cursor persistently in your computer.

  • In most cases, the service IP address list remains unchanged unless resolution fails.

  • We recommend making the service IP address list dynamically configurable to reduce the time for updates to take effect and minimize impact.

If all HTTPDNS service IP addresses fail to respond, fall back to local DNS, which is the native DNS chain of the operating system. If you use OkHttp as the network library to integrate HTTPDNS on Android, use the following code for local DNS resolution:

List<InetAddress> result = okhttp3.Dns.SYSTEM.lookup(host);
val result: List<InetAddress> = Dns.SYSTEM.lookup(host)

For iOS, avoid performing Host replacement or request interception, and the original request will remain unchanged:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
// Send the request.
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
    if (error) {
        NSLog(@"error: %@", error);
    } else {
        NSLog(@"response: %@", response);
    }
}];
[task resume];
var request = URLRequest(url: url)
// Send the request.
let session = URLSession.shared
let task = session.dataTask(with: request) { (data, response, error) in
    if let error = error {
        print("error: \(error)")
    } else {
        print("response: \(response?.description ??  "")")
    }
}
task.resume()
  1. Non-blocking resolution

    Use asynchronous methods in your apps to access HTTPDNS so that your business is not blocked waiting for resolution results.

2. Performance optimization

Scenario: Performance bottlenecks caused by frequent queries

Background information

If HTTPDNS is queried for domain name resolution on every network request, business latency and bandwidth consumption increase significantly. Because resolution results have a TTL cache value, you can cache results based on this value.

Solutions

  1. Local cache

    • According to the DNS standard RFC 104, the resolution results can be cached based on the TTL value.

image
Note
  • The TTL value is the ttl field in the HTTP API response.

  • If the cache is not hit or expires, you must initiate a resolution request and update the cache.

  1. Pre-resolving

Note

When the cache is about to expire, for example, at 80% of the TTL, you can resolve the relevant domain names and cache the results locally. Pre-resolve commonly used domain names and cache the results when the application is started. Pre-resolving reduces service access latency but increases the number of resolution requests. We recommend that you use pre-resolving only for hotspot domain names.

  1. Connection reuse

    Enable the connection reuse feature of the HTTP client to reduce TCP connection setup time and decrease HTTPDNS resolution latency.

  2. Persistent caching

    Cache the most recent resolution results persistently. After the app restarts, the results are loaded from the persistence layer first, which improves initial loading speed.

Note
  • An IP address may have expired on its first use (its TTL has expired), but it can still be used in most cases.

  • With persistent caching enabled, the results of domain name resolution are affected when the app starts for the first time or the network type changes. After persistent caching is enabled, all resolution requests are forwarded to the HTTPDNS server and the local cache is updated.

3. Resolution quality optimization

Scenario: Access latency caused by cross-ISP resolution

Background information

When you use CDN-accelerated domain names or domain names configured with intelligent routing, the client may cache the resolved IP address based on the TTL value. If the network environment changes, for example, switching between 4G and Wi-Fi, the cached IP address may no longer match the optimal route for the new network, potentially degrading business network performance.

Solutions

  1. Network environment monitoring

    • Monitor client network changes, such as switching from Wi-Fi to mobile data.

    • Proactively refresh the local cache to keep resolution results aligned with the current network environment.

Important

Refreshing resolution results for all domains generates additional traffic.

  1. Speed testing and sorting

    Use ICMP or TCP asynchronous testing to rank resolution results and prioritize the IP address with the fastest response time.

Important

This method may impact the original load balancing strategy of the business servers.

4. Security optimization

Scenario: A resolution request is hijacked or leaked

Background information

A resolution API without authentication poses security risks. Third parties may exploit it to steal traffic and incur costs.

Solutions

  1. Authentication resolution

    We recommend using authenticated API operations for domain name resolution. You can choose whether to disable API operations without authentication in the HTTPDNS console.

    • HTTPDNS uses a secret key to generate an encrypted string and includes it in the request for authentication. The secret key itself is not transmitted, which reduces exposure risk and protects resolution requests.

    • For more information, see Implement authenticated access.

  2. Use HTTPS for secure communication

5. Troubleshooting

To efficiently locate issues, generate a session ID when the app starts to uniquely identify a single app session lifecycle. Include this session ID in HTTPDNS requests. If a problem occurs, the HTTPDNS technical support team can use the session ID to troubleshoot. The session ID is in the [a-zA-Z0-9]{12} format.

Example: http://203.107.xxx.xxx/{accountId}/sign_d?host=www.aliyun.com&t=1573XXXX&s=60c7XXXXXX&sid=1234567890ab

6. Summary

By following these optimization practices, developers can achieve highly available, low-latency, and secure HTTPDNS integration through APIs in complex network environments while improving overall resolution quality.