An API Server without Caching or Batching
Learn how to implement an API server without using caching or batching.
We'll cover the following
Before we start diving into this new challenge, let’s implement a small demo server that we’ll use as a reference to measure the impact of the various techniques we’re going to implement.
Example
Let’s consider an API server that manages the sales of an e-commerce company. In particular, we want to query our server for the sum of all the transactions of a particular type of merchandise. For this purpose, we’re going to use a LevelUP database through the level npm package. The data model that we’re going to use is a simple list of transactions stored in the sales sublevel (a subsection of the database), which is organized in the following format:
transactionId {amount, product}
The key is represented by transactionId
and the value is a JSON object that contains the amount of the sale (amount
) and the product type (product
).
The data to process is really basic, so let’s implement a simple query over the database that we can use for our experiments. Let’s say that we want to get the total amount of sales for a particular product. The routine would look as follows (the totalSales.js
file):
Get hands-on with 1400+ tech skills courses.