Performance, Latency & Regions

Last Edit: Feb 02 2020

You can view the current API status on the Status Page.

You can expect your feed to load in about 10ms. The most common cause of slower performance is latency. You can improve this by selecting the closest data center to you.

Stream is currently available in different locations. When you create an application, you should select the region that is closest to you to get the best latency:

  • US East - Virginia: us-east

  • Europe West - Ireland: dublin

  • Asia - Singapore: singapore

  • Asia - Tokyo: tokyo

Make sure you provide your application region when initializing the client:


// connect to the us-east region
const client = stream.connect('', 'YOUR_API_SECRET', 'APP_ID', {'location': 'us-east'});
                    

# connect to the us-east region
import stream
client = stream.connect('', 'YOUR_API_SECRET', location='us-east')
                    

client = Stream::Client.new('','YOUR_API_SECRET', 'APP_ID', :location => 'us-east')
                    

$client = new GetStream\Stream\Client('', 'YOUR_API_SECRET');
$client->setLocation('us-east');
                    

Client client = Client.builder("API_KEY", "API_SECRET").region(Region.US_EAST).build();
                    

// connect to the us-east region
client, err := stream.NewClient(
    // API key
    "",
    // API secret
    "YOUR_API_SECRET",
    // API region
    stream.WithAPIRegion("us-east"),
)
if err != nil {
    panic(err)
}
                    

// connect to the us-east region
let client = Client(apiKey: "", 
                    appId: "APP_ID", 
                    token: "FEED_TOKEN", 
                    baseURL: BaseURL(location: .usEast))
                    

var opts = StreamClientOptions.Default;
opts.Location = StreamApiLocation.USEast;
var client = new StreamClient("", "YOUR_API_SECRET", opts);
                    

Enrichment & Performance

Another common cause of slow feed performance is the enrichment step. Often you'll send references to your database in the activities. When loading your feed you need to run specific database queries to load the latest version of this data.

In cases like this, there are three things to keep in mind:

  1. Batch all the database queries. Never run N queries for N items in the feed.

  2. Cache the lookup using the primary key with a model layer cache (recommended only for large apps).

  3. Use Stream collections and user endpoints to store data and get the best performance.

More information on how enrichment works can be found here.