var opts = StreamClientOptions.Default;
opts.Location = StreamApiLocation.USEast;
var client = new StreamClient("{{ api_key }}", "{{ api_secret }}", opts);
Performance, Latency & Regions
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 - Ohio:
ohio
Europe West - Ireland:
dublin
Asia - Singapore:
singapore
Asia - Tokyo:
tokyo
Asia - Mumbai:
mumbai
Make sure you provide your application region when initializing the client:
// connect to the ohio region
const client = stream.connect('{{ api_key }}', '{{ api_secret }}', '{{ app_id }}', {'location': 'ohio');
# connect to the ohio region
import stream
client = stream.connect('{{ api_key }}', '{{ api_secret }}', location='ohio')
client = Stream::Client.new('{{ api_key }}','{{ api_secret }}', '{{ app_id }}', :location => 'ohio')
$client = new GetStream\Stream\Client('{{ api_key }}', '{{ api_secret }}');
$client->setLocation('ohio');
Client client = Client.builder("{{ api_key }}", "{{ api_secret }}").region(Region.ohio).build();
// connect to the ohio region
client, err := stream.New(
"{{ api_key }}",
"{{ api_secret }}",
stream.WithAPIRegion("ohio"), // API region
)
if err != nil {
panic(err)
}
// connect to the ohio region
let client = Client(apiKey: "{{ api_key }}",
appId: "{{ app_id }}",
token: "{{ feed_token }}",
baseURL: BaseURL(location: .ohio))
final client = StreamFeedClient.connect('{{ api_key }}', secret:'{{ api_secret }}', appId:'{{ app_id }}', options: StreamHttpClientOptions(location: Location.ohio));
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:
Batch all the database queries. Never run N queries for N items in the feed.
Cache the lookup using the primary key with a model layer cache (recommended only for large apps).
Use Stream collections and user endpoints to store data and get the best performance.
More information on how enrichment works can be found here.