Home Projects Portfolio Dashboard Export PDF Log in

Streamlining Service Architecture: Removing Unnecessary Dependencies in North-South

In the ongoing development of the North-South project, our focus has been on refining service efficiency and simplifying our dependency stack. As we iterate on our backend services, we continuously re-evaluate the libraries that power our core business logic, specifically within our commission calculation modules.

The Situation

Our commission service had become increasingly bloated due to the inclusion of heavy-duty browser automation tools for PDF generation. While tools like Puppeteer are excellent for headless browsing, they are often overkill for server-side document generation, adding significant overhead to our container images and deployment pipelines.

The Refinement

We decided to strip away these unnecessary dependencies. By moving towards lightweight, native, or specialized libraries for document generation, we significantly reduced the footprint of our NestJS services. This change not only improved our startup times but also eliminated potential points of failure introduced by heavy environment-specific binaries.

While cleaning up the service, we also addressed a logical flaw in our commission distribution engine. Previously, the anticipation of payments was not being handled with the precision required for high-volume transactions.

The Technical Shift

By leveraging the Repository Pattern and Dependency Injection, we were able to isolate the commission calculation logic, making it easier to test and modify without side effects. In TypeScript, this allows us to inject specialized providers to handle document formatting rather than relying on a heavy browser engine.

@Injectable()
export class CommissionService {
  constructor(private readonly repository: CommissionRepository) {}

  public async calculateDistribution(id: string): Promise<void> {
    const data = await this.repository.findById(id);
    // Optimized logic for handling anticipations
    const distribution = this.processAnticipations(data);
    await this.repository.save(distribution);
  }
}

The Outcome

Removing Puppeteer reduced our build times and cloud resource consumption. Furthermore, the refined logic in the commission service ensures that payment distributions are accurate, preventing the errors we previously encountered with anticipations.

The Takeaway

Always question your dependency tree. If a library brings a massive footprint but serves a trivial task, look for a more focused alternative. Start by auditing your package.json for unused or oversized dev dependencies and consider if native or lightweight solutions can replace them.


Generated with Gitvlg.com

Streamlining Service Architecture: Removing Unnecessary Dependencies in North-South
RIVAS SALTOS DANIEL RUBEN

RIVAS SALTOS DANIEL RUBEN

Author

Share: