When working with Netlify, the addition of PolyScale can dramatically reduce response times by serving cached responses that are located closer to your applications and edge functions. Whereas your database is hosted in a single location, Netlify edge functions are global, which means that user requests are served from the closest Netlify PoP. However, if your Netlify edge function is data-driven, utilizing a database, the benefit of serving the request from close by is mitigated by the time required to get to the distant database.
PolyScale can be set up in just minutes and allow your data-driven edge function to be more performant.
This guide explains how to connect Netlify to a PolyScale cache.
This tutorial assumes that you have already connected a database to a Netlify edge function. If you have not already, you can read more about retrieving database data from a Netlify Edge function in this blog post.
To connect to your database via PolyScale instead, it is as simple as creating a PolyScale cache, and then replacing your original database connection details with those provided by PolyScale.
Step 1: Create your PolyScale Cache
Before creating the cache, get your current database host and port, as you will need them to set up PolyScale.
- In your PolyScale account, click on the New Cache button
- Give the cache a Name
- Select the Type of database you have
- Enter the Host address for your existing database
- Enter the Port used for your existing database
- Click Create
When you create your cache, PolyScale will automatically run a network test to ensure we can make a TCP connection to your database from our PoPs. If you see any locations cannot connect, you can add them to you IP Allow List.
You now have a working database cache configured.
PolyScale will automatically run a network connectivity test to ensure your database is accessible from all PolyScale PoPs. Be sure that you have added PolyScale's source IP addresses to your allow-list. You can read more here.
Step 2: Connect to your PolyScale Cache
To connect to the origin database via PolyScale simply update any client applications as follows:
Step 2.1: Use a PolyScale database hostname and port:
Using your PolyScale cache is simple -- instead of connecting to your database directly, you'll replace your original host with the PolyScale host -
Depending on your database type, select the appropriate port choice below.
- SQL Server
Step 2.2: Provide a PolyScale Cache ID as part of the connection string:
The Cache ID can be found under the
Settings tab of any cache (as detailed in
Step 2 above). For MySQL, MariaDB and SQL Server, this is prepended to the database username
seperated with a hyphen (see example below). For PostgreSQL, an
application_name property containing the PolyScale Cache ID is required as part
of the connection string e.g.
For further details, see Getting Connected.
That's it. Now your Netlify edge function is connected to PolyScale.