Query Builder Package: From Individual Chaos to Collective Consistency

Sinem Elif Haseki
Insider Engineering
3 min readFeb 27, 2024

Introduction

In the dynamic world of software development, aligning multiple products with consistent and efficient service request protocols is a critical challenge. This article delves into the role of a new query builder package in revolutionizing this process, emphasizing its necessity, benefits, and drawbacks.

The Genesis of a Streamlined Approach

Before: The landscape of service requests was fragmented. Each product team wrote its own code to fetch analytics, leading to countless issues such as inconsistency, higher error rates, and maintenance challenges.

After: Introduction of the TypeScript query builder package for unification.

Image 1: Different Products sending requests to the same SoT, before and after Query Builder Package

Unveiling the TypeScript Query Builder Package

Prior to the adoption of the new Query Builder Package, our architecture had a different collection of methods and services, each tasked with retrieving data from the same source of truth. This fragmented approach necessitated that various teams independently develop and manage multiple services. Such a setup not only increased the complexity of our operations, but also introduced significant challenges in maintaining consistency and efficiency, particularly as new requirements emerged from our source of truth-side. This scenario led to the pressing need for a streamlined, unified system to enhance our data fetching processes and ensure a cohesive strategy across all product lines.

The new package in question offers a structured approach to service requests, encompassing pre-filters, log types, and any other parameter needed. Its integration across products ensures uniformity and efficiency.

Consider the usage pattern:

builder
.setPrefilters(prefilters)
.setLogTypes(logTypes)
.fetch()

Now, products simply provide their parameters to these methods instead of writing and maintaining their own code having basically the exact same functionality, significantly reducing the complexity and bespoke nature of each service request.

Advantages of the Query Builder Package

  1. Uniform Request Handling: Achieves consistency across products.
  2. TypeScript’s Type Safety: Minimizes errors and enhances code quality.
  3. Modular and Readable Code: Facilitates better maintenance and readability.
  4. Flexible and Customizable: Adapts easily to varying requirements.
  5. Streamlined Integration: Simplifies the integration process, saving time and resources.
  6. Cross-Platform and Language Compatibility: Exceptionally versatile, the package is compatible with various platforms and languages, including JavaScript and Ruby, and is usable in both web and mobile environments. This broad compatibility ensures that it can be seamlessly integrated into a wide range of applications.

Challenges to Consider

  1. Learning Curve: The know-how for the new package must be passed to all product developers to use and debug it.
  2. Maintenance and Updates: Ongoing responsibility for the package’s upkeep.
  3. Dependency Management: Managing its dependencies is crucial for smooth integration.
  4. Authentication Concerns: Integrating secure authentication methods, like tokens, to ensure service security is a critical challenge.

Conclusion

Transitioning from a disjointed approach to a unified query builder package has marked a substantial leap in managing service requests, where the target service is the same and only parameters are changing. We decreased the number of potential bugs being born from inconsistencies. This is quite a crucial approach when there are external dependencies for fetching important data.

If you are interested in more practical tricks, especially in JS, you can check this article by Berkan Sezer, Senior Frontend Developer at Insider.

--

--