7 minutes read

Xano performance optimization guide

Xano performance optimization guide

What is Xano?

The goal of this post is not to give an overview of Xano’s overall capabilities, but to give you some tips how to improve the Xano performance using database indexing, response caching and other methods. We wrote an extensive overview of it’s capabilities in a separate post.
Xano: Ultimate tool for no-code backend development

However in short, Xano a no-code development platform to build backend for your applications.
There are plenty of different functionalities, however the core of the platform consist of following functionalities:

  • Authentication – Comes out of the box with JWE tokens and pre-built OAuth authentication solutions.
  • No-code API builder – Allows you to build complex business logic and workflows (CRUDs can be generated automatically).
  • Flexible database – Managed PostgreSQL database with the ability to manage DB triggers, indexes, data validations, etc.
  • Recurrent tasks – easy setup of recurrent workflows, which are basically equivalent to CRON jobs

In case you want to make sure your app is fast and performance-optimized, we offer Xano audits (potentially combined with WeWeb audit).

How to improve the overall Xano performance?

Xano offers several ways how to optimize the performance of its queries and API endpoints in general. The aim of this guide is to continuously add some best-practices how to optimize the performance of your Xano application.

We want to avoid providing general app architecture patterns and anti-patterns, but rather focus more on

Database indexing

Let’s not deep-dive onto technicalities how PostgreSQL DB indexes work in general, but rather focus how and when should you use it in Xano.

Xano database indexing

When to use DB indexes in Xano?

Simple way of putting this would be that you want to create an index, when you need to improve the performance of your database query. As you can find in Xano documentation, main use-cases are following:

  • When you have a query that takes a lot of time to return the data
  • Query consist of simple operators, such as item.amount <0 and user.name = “Juraj”
  • The table you are looking in, has at least 10 000 records?

When should I avoid applying DB indexes in Xano?

  • If you table has a lot of insert/update operations
  • if the combination of fields in the index has only few unique values (so called low cardinality)
  • Non-selective queries – if usually the query return a large percentage of the table’s data, you should avoid using DB indexes

What types of indexes can I add to Xano table?

There are several types of indexes, each for slightly different set of use-cases.

  • GIN (Generalized Inverted Index) – They are used mainly to search through JSON data. For example: “search for data, where contact_data (JSON) contains key-value pair: {"country":"Slovakia"}
  • Index – used for standard, simple queries. Based on whether you need to increase the performance of queries which are based on one or multiple condition, you can also create simple or composite indexes (so suppose you need to optimize a query where you are searching users based on age and location, then you can create a composite index with 2 columns – age and location
  • Unique – used to enforce unique values in the columns (let’s say secondary ID, slug, etc…)
  • Spatial – used for searching geographical data
  • Search – powerful type of index, that can be used together with Xano’s fuzzy search. (i.e. searching text data based on text similarity and not necessarily exact match
Types of Xano database indexes

How can I create a new index in Xano?

Let’s look directly in Xano’s documentation, where you can find step-by-step guide for creating a DB index in Xano.

API and Function caching

What is caching?

Data caching can decrease response time of some of your API endpoints from seconds to milliseconds. Xano uses REDIS caching – which uses in-memory data storage. So when calling an API endpoint, instead of actually querying the data and doing whatever the logic that is in the function stack, it will return “cached” response immediately.

Xano response caching

When should I implement response caching in Xano?

There are two “types” of response caching in Xano, but they work in exactly the same way:

  • API response caching
  • Function response caching

We recommend to use response caching, which can significantly improve the overall performance of your backend. (it’s not only that cached endpoints will be faster, but they will also free additional computing resources that can be used for un-cached data back-end operations)

  • Static or rarely-changing data – when the underlying data doesn’t change frequently, or the do not change at all
  • Expensive queries – if the underlying data means that you need to make super-complex database query that would normally take 10 seconds or more. Underlying data might change frequently, but you can configure reset of cache for example every one hour
  • Predictable data changes – if you know the exact frequency of when the data in the underlying query are being changed (e.g. daily recalculations), you can configure that cache will reset right after the data update takes place

When should I avoid using response caching in Xano?

What you need to understand when implementing response caching: If API or function is cached, it doesn’t query the data in real-time, nor does it execute any other operations defined in the function stack. So either avoid response caching or handle it with high level of caution in following cases:

  • You are querying highly dynamic data (e.g. recent posts on social network) and you actually need to return “current” data
  • Any function or endpoint, where you perform write or update operations. Because they will not be executed.
  • Personalized responses – if the data you are querying are different for each user, first be sure that you use private caching (can be easily setup in Xano)

Use add-ons when querying the data

What are Xano addons?

Addon is a feature in Xano that allows you to very easily enrich the data in your database query. So instead of doing multiple queries and then merging the data together, it allows you to return data from different data sources within a single database query.

Xano addons

When to use Xano addons?

You want to use addons mainly when you need to combine data from different data sources. Let’s see two examples:

Example 1enrich data based on “foreign key”
Suppose you have a table called event. One of the event’s properties is a location_id, which refers to a separate table with locations. (that contains info such as Country, city etc.)
If you want to fetch all of the properties of location in your main query, you can easily create an addon for that. (otherwise, the query would return only the location_id)

Example 2aggregations

Second example is a bit different. Suppose the use-case is that you have a list of movies and then you have a separate table with movie reviews.
You want to create an addon, that in addition to movie’s properties will also return the count of reviews for given movie.

Less function blocks, more filters

To illustrate what do we mean, let’s have an example:

We have table with posts (for example social network posts), where each post has a “content”. We want to create a function, that will take as an input these posts and and perform series of operations: remove dots, commas, capitalize all words, trim entire string, split by ” ” and then join by “—“.

Let’s compare different approaches by doing these operations on 1000 records

Using separate function blocks(avg ~ 1.5s)

For each of the operations, we use single function block in Xano, as you can see below.

Xano function stack

Using Xano filter within a single block (avg ~ 0.75s)

Instead of using a separate function block for each operation, we use single function block with multiple filters. As you can see, we’ve achieved approximately 50% lower processing time, compared to the approach of multiple function blocks.

Custom code might help sometimes

Let’s continue with the example above. We know that Xano is primarily no-code back-end development platform, but it never hurts to use some code when you need to optimize Xano APIs for speed. (most of the cases, you’ll be just fine without a single line of code)

By using AWS lambda code, we were able to decrease the overall time by another 60%. (using .forEach and .map was almost exactly the same from performance perspective)
Just have in mind that for huge arrays, .forEach can be more memory efficient.

Xano JavaScript lambda function

Asynchronous processing

Not everything needs to be synchronous. Xano has a feature called “Post process” which allows you to execute part of the API business logic after the API returns the response.

This is especially useful, when you don’t need to wait for all operations to be executed.

Example when using async function block might be useful:

  • When user signs up and the confirmation email is part of the signup process, you can send the email in “post process” block. Waiting for API response from email provider is not necessary to return success API response

However be careful with post-process blocks in cases, when user needs to know when something has failed.

Conclusion

Every time your application needs to scale with growing number of users, their data or growing number of features you will face some performance challenges. This is not different whether you are building your product in no-code or with traditional development approach.

If you would like to help with your Xano development, let’s have a quick call to find out how we can help you.