← PORTAFOLIOPORTFOLIO / proyectos / escaneo-masivo

// PRJ_008 · 2024

Generación masiva de guíasBulk shipping labels

Rendimiento · PostgreSQLPerformance · PostgreSQL

Las guías de envío se generaban una por una. Ahora un procedimiento en la base de datos las genera por lote.Shipping labels used to be generated one at a time. Now a database procedure generates them in batches.

En detalleIn detailAutomaticé con un procedimiento almacenado en PostgreSQL, invocado desde NestJS, la generación masiva de guías de envío, que antes se hacía una por una. Lotes de más de 10.000 guías, en un módulo con arquitectura hexagonal.I automated bulk shipping-label generation, previously done one at a time, with a PostgreSQL stored procedure called from NestJS. Batches of more than 10,000 labels, in a module with a hexagonal architecture.

RolRole
Desarrollador backendBackend developer
AñoYear
2024
CódigoSource
privado — trabajo de empresaprivate — company work
Stack
NestJS · PostgreSQL · TypeScript

// IMPACTO// IMPACT

+10.000+10.000
guías por lotelabels per batch
PostgreSQLPostgreSQL
motorengine
HexagonalHexagonal
arquitecturaarchitecture

El problemaThe problem

Las guías de envío se generaban una por una. Con lotes de miles, la operación dependía de un proceso lento y repetitivo.Shipping labels were generated one at a time. With batches of thousands, operations depended on a slow, repetitive process.

Cómo lo resolvíHow I solved it

Moví la generación a un procedimiento almacenado en PostgreSQL que trabaja por lote en vez de por fila, invocado desde la API en NestJS. El módulo seguía una arquitectura hexagonal, con el dominio separado del acceso a datos, y hoy procesa lotes de más de 10.000 guías.I moved generation into a PostgreSQL stored procedure that works per batch instead of per row, called from the NestJS API. The module followed a hexagonal architecture, with the domain separated from data access, and it now handles batches of more than 10,000 labels.

Arquitectura y stackArchitecture & stack

  1. [01]Operación
  2. [02]API NestJS
  3. [03]Casos de uso
  4. [04]Procedimiento PostgreSQL
  5. [05]Guías
  • NestJS
  • PostgreSQL
  • TypeScript

Lo que aprendíWhat I learned

01 //

Por lote, no por fila

La mejora vino de cambiar la forma de la consulta, no de agregar máquina.

02 //

Hexagonal para poder probar

Con el dominio aislado se podía probar la lógica sin levantar la base.

03 //

La base hace lo que sabe hacer

Un procedimiento en PostgreSQL resolvió en la base lo que en la API eran miles de viajes de ida y vuelta.

01 //

Per batch, not per row

The improvement came from changing the shape of the query, not from adding hardware.

02 //

Hexagonal so it can be tested

With the domain isolated, the logic could be tested without bringing up the database.

03 //

Let the database do its job

A PostgreSQL procedure solved in the database what in the API was thousands of round trips.