Are you an Edgio customer facing uncertainty? Discover how Macrometa ensures continuity and delivers high-performance solutions for your business.
Pricing
Log inTalk to an expert
Tutorial

Building a Hyper-Distributed Shoe Store Inventory API with Macrometa

Post Image

Imagine you're running an online shoe store that caters to a global customer base. Your customers expect a seamless, low-latency experience when browsing your catalog, and your development team needs an efficient way to build and manage the backend. Macrometa, a hyper-distributed cloud platform, can help you achieve this.

In this blog post, we'll discuss the advantages of using Macrometa over traditional centralized cloud platforms and walk you through the process of building a shoe store catalog API that provides CRUD and search functionalities.

Why Macrometa?

Macrometa's Global Data Network (GDN) architecture simplifies the process of building and managing a geo-distributed application. It provides a single API to access key-value, document, and graph data models, along with built-in search, pub-sub, queueing, complex event processing, and general-purpose computing capabilities.

This stands in contrast to traditional centralized cloud platforms, where developers must design, build, and manage applications that are typically using many various tools and single-purpose databases to achieve similar functionality. Macrometa's platform ensures data consistency and synchronization across multiple regions using proprietary CRDT technology, providing significant advantages for developers working on applications with a global audience.

Macrometa Search is an advanced full-text search engine designed to support key values, documents, and graphs as data models. Unlike traditional full-text indexes, Macrometa Search offers a highly configurable and customizable experience, combining Boolean and generalized ranking retrieval techniques to refine search results. It ranks all Boolean-approved results by relevance using the Vector Space Model in conjunction with BM25 or TF-IDF weighting schemes.

Macrometa Search is equipped with state-of-the-art indexing and search capabilities, enabling sophisticated search operations on multi-model data storage without the need to reformat data.

Macrometa Search: Views and Analyzers

Search views are virtual collections that enable fast full-text searching across multiple linked collections.

Analyzers parse input values and transform them into sets of sub-values for tokenization, language-specific word stemming, case conversion, and removal of diacritical marks.

Macrometa Search features are integrated into C8QL as a SEARCH operation and a set of C8QL functions. This integration allows for a wide range of use cases, such as performing federated full-text searches over product descriptions in a webshop, retrieving and ranking research database information by relevance, or querying a dataset of movies for specific titles and sorting the results by best matching while favoring movies with longer durations.

Key features of Macrometa Search include:

  • Complex searches with Boolean operators: Perform intricate search operations using Boolean operators to combine multiple conditions and refine results.
  • Relevance-based matching: Automatically rank search results based on their relevance to the query.
  • Phrase and prefix matching: Search for exact phrases or partial matches to enhance the accuracy of results.
  • Custom ranking and relevance tuning: Customize the ranking algorithm and fine-tune the relevance of search results to suit specific use cases.
  • Configurable analyzers and tokenization: Configure analyzers for tokenization, language-specific word stemming, case conversion, and removal of diacritical marks.
  • Retrieval of both documents and projections of documents: Retrieve complete documents or specific projections based on search criteria.
  • Combinable search queries across multiple data models and access patterns: Seamlessly perform search queries across various data models, such as key-value pairs, documents, and graphs.
  • Geo-replicated search indexes for instant results: Benefit from low-latency search results through the geo-replication of search indexes.

Macrometa Search offers a powerful, flexible solution for building advanced search functionality into applications. Its extensive features, configurability, and seamless integration with C8QL make it an invaluable tool for developers looking to create responsive and engaging applications for global audiences.

Building a Shoe Store Inventory API

To demonstrate how easy it is to create a geo-distributed shoe store inventory API with Macrometa, we'll guide you through the following steps:

Create a document collection called inventory: In the Macrometa console, create a new document store collection named inventory.

Import the shoe-inventory.json file: Import the JSON file containing shoe catalog data into the inventory collection.

Dataset: shoe-inventory.json

Example of the data model:

{
    "brand": "Adidas",
    "category": "Running",
    "color": "Grey One",
    "name": "Adidas Ultraboost 21",
    "price": 180,
    "product_id": "011",
    "quantity": 20,
    "size": 9
}

After importing the file we should have 50 documents in the collection!

Write your first query: Write your first query to fetch all documents in the inventory collection:

FOR docs IN inventory
RETURN docs

Create a Query Worker (API endpoint): Name your Query Worker saveProduct and write an INSERT statement to add a new product to the inventory collection. The @ symbol in this query example is a `binding parameter`. They allow you to leave values as wildcards, so you can pass values along when you call the API to dynamically write and read your data.

INSERT {

brand: @brand,

category: @category,

color: @color,

name: @name,

price: @price,

product_id: @product_id,

quantity: @quantity,

size: @size

}

INTO inventory

Create a search view for the inventory: Enable high-performance search on the inventory collection by creating a search view named inventory_view.

Fields to map from above:

  • size
  • quantity
  • price
  • name
  • brand

Query the newly created view: Write a query to search the inventory_view by shoe name. Use the ANALYZER function to perform various search operations and filter results based on size and price range.

let keyword = LOWER(to_string(@keyword))
let minSize = @Min_Size
let maxSize = @Max_Size
let minPrice = @Min_Price
let maxPrice = @Max_Price

FOR product IN inventory_view
  SEARCH ANALYZER(
    (STARTS_WITH(product.name, keyword) OR
    STARTS_WITH(product.brand, keyword) OR
    PHRASE(product.name, keyword) OR
    PHRASE(product.brand, keyword)) AND
    (IN_RANGE(product.size, minSize, maxSize,true,true) AND 
    IN_RANGE(product.price, minPrice, maxPrice,true,true)),  "text_en"
  )
  RETURN KEEP(product,
    "name",
    "brand",
    "price",
    "size", 
    "quantity"
  )

Save the query as a Query Worker: Save the search query as a Query Worker named inventory-search, and now you have a fully functional search API!

By following these steps, you'll have fully functional, geo-distributed shoe store inventory APIs for CRUD and Search that provide a low-latency experience for users around the world.

Get started today with Macrometa

Macrometa offers a better developer experience and makes building distributed applications easier compared to traditional centralized cloud platforms. Its global data platform, simplified data management, and built-in functionalities such as Query Workers and Search Views enable developers to easily build applications like a shoe store catalog API, providing a seamless experience for end-users.

Request a 30 day trial to get started today, or schedule a call with a solutions architect.

Follow the series here; in my next posts, I’ll be showing you how to use Graphs to create a recommendation engine and Stream Workers (complex event processing) to implement real-time inventory management!

Photo by Amit Lahav on Unsplash

Related Posts