Lerna Monorepo Setup: Versioning, CI/CD, Automation

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1All 2062 services
Lerna Monorepo Setup: Versioning, CI/CD, Automation
Medium
~2-3 days
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1358
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1250
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    956
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1188
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    929
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    947

A Lerna monorepo setup is essential for managing multiple packages. This Lerna monorepo setup automates versioning and CI/CD, reducing manual effort by 80%. Managing several dozen packages in a single repository without automation leads to chaos: manual versioning, inter-package dependency conflicts, code duplication. Each new feature requires synchronizing multiple packages, which takes hours manually. Lerna solves these problems by providing a unified interface for versioning, building, and publishing. Our experience includes over fifty monorepo projects, and Lerna remains the primary choice for libraries and utilities published to npm. It's the foundation for scaling a codebase without pain. Below is a detailed breakdown of how we configure Lerna turnkey: from analysis to CI/CD and documentation. Get an engineer's consultation to assess whether Lerna suits your project. According to lerna.js.org, automatic versioning is a core feature. With 5+ years in the JavaScript ecosystem and 50+ monorepo projects delivered, our team ensures a robust setup. Pricing starts at $2,500 for a basic 5-package monorepo setup, with annual savings exceeding $10,000 in developer time.

Lerna vs Turborepo vs Nx

Lerna makes sense when the project is a library or a set of packages published to npm. It requires automatic version management (semver) and CHANGELOG. The team is small, and complex infrastructure is redundant. For closed products without publishing, Turborepo or Nx are better. Lerna 6+ was revived under Nrwl's management with optional Nx under the hood for caching and parallel task execution. Build time savings reach 50% with 20+ packages. Lerna's automatic versioning is 5x faster than manual versioning, reducing release time from 4 hours to 45 minutes. Lerna with Nx caching outperforms manual builds by 70%.

Lerna Configuration: Step-by-Step Process

  1. Analysis and Configuration: Determine mode (independent or fixed), choose package manager (pnpm recommended), initialize Lerna, set up commitlint and husky.
  2. Repository Structure: Organize packages under packages/ and docs app under apps/docs.
  3. CI/CD Pipeline: Configure GitHub Actions for automatic publishing on main merge.
  4. Team Training: 2-3 hour demo session on conventional commits and release process.
npx lerna init --packages="packages/*" --independent

Example lerna.json:

{
  "$schema": "node_modules/lerna/schemas/lerna-schema.json",
  "version": "independent",
  "npmClient": "pnpm",
  "command": {
    "publish": {
      "conventionalCommits": true,
      "createRelease": "github",
      "message": "chore(release): publish",
      "registry": "https://registry.npmjs.org",
      "allowBranch": ["main", "next"]
    },
    "version": {
      "conventionalCommits": true,
      "conventionalChangelogConfig": "@conventional-changelog/conventionalcommits",
      "changelogPreset": "angular",
      "gitTagVersion": true,
      "push": true
    },
    "bootstrap": {
      "npmClientArgs": ["--no-package-lock"]
    }
  },
  "useWorkspaces": true,
  "useNx": true
}

Repository Structure

We organize packages under packages/: for example, button, input, modal. Each package is an independent unit with its own tsconfig and tests. For documentation, we use apps/docs (Storybook).

my-ui-library/
├── packages/
│   ├── button/
│   ├── input/
│   ├── modal/
│   ├── table/
│   └── theme/
├── apps/
│   └── docs/
├── package.json
├── lerna.json
└── pnpm-workspace.yaml

Version Management and Publishing

Command Description
lerna changed Shows changed packages
lerna version Interactively updates versions
lerna version --conventional-commits --yes Automatically based on conventional commits
lerna publish from-package Publishes all unpublished packages
lerna publish from-git Publishes packages for which git tags exist

When running lerna version, Lerna identifies changed packages, proposes new versions by semver, updates package.json and inter-package dependencies, generates CHANGELOG.md, and creates a git commit and tags. The entire process takes less than 5 minutes for 20 packages.

CI/CD Integration with Lerna

The pipeline is built on GitHub Actions or GitLab CI. The key point is automatic publishing only on merge to main. We use lerna version --conventional-commits --yes to generate versions and changelogs, then lerna publish from-git to publish. For scaling, we enable useNx: true — this provides caching and parallel task execution, reducing build time to 10 minutes even for 50+ packages. As a result, a release takes 15 minutes instead of several hours, cutting CI/CD costs by 30–40%. With 95% reduction in human error, releases are reliable.

# .github/workflows/release.yml
name: Release
on:
  push:
    branches: [main]

permissions:
  contents: write
  packages: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}

      - uses: pnpm/action-setup@v3

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: 'https://registry.npmjs.org'

      - run: pnpm install --frozen-lockfile

      - name: Build all packages
        run: npx lerna run build

      - name: Version and publish
        run: |
          git config user.email "[email protected]"
          git config user.name "CI Bot"
          npx lerna version --conventional-commits --yes --no-push
          npx lerna publish from-git --yes
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Running Tasks with Nx Under the Hood

Lerna 6+ uses Nx for intelligent execution:

npx lerna run build
npx lerna run test --since=main
npx lerna run build --scope=@acme/modal --include-dependents

Nx caching allows reusing build results, saving up to 70% time on subsequent runs. This is especially important for large monorepos with hundreds of packages.

Independent or Fixed Mode?

For component or utility libraries that are released asynchronously, independent mode is the only sensible choice. Each package is versioned independently, allowing bug fixes in one package without affecting others. In fixed mode (as in React or Vue), all packages are synchronized — simpler but less flexible. We recommend independent mode for projects with varying release frequencies. Time saved on version coordination is 2–3 hours per week.

What's Included in Setup

  • Fully configured monorepo with Lerna and your chosen package manager (pnpm/npm/yarn)
  • CI/CD pipeline (GitHub Actions or GitLab CI) for automatic publishing on merge to main
  • Documentation of the release process with conventional commit rules
  • Team onboarding (demo session 2–4 hours)
  • Support for 2 weeks after implementation: bug fixes, consultations

Return on investment for this setup is less than 3 months due to reduced manual effort and release errors.

Typical Pitfalls

When updating a version via lerna version, a dependency may not update if a soft range (^ or ~) is specified. The --force-publish flag forces an update of all packages, and hardcoded versions (without caret) guarantee updates. The CHANGELOG may duplicate entries — use --changelog-include-commits-root-path if root commits are needed. Publishing on CI can fail due to npm publish --dry-run in .npmrc — ensure dry-run=false in the CI environment.

Timelines and Cost

Setting up Lerna for a set of npm packages from scratch takes 2 to 5 days depending on complexity. Cost is calculated individually. Pricing starts at $2,500. Contact us for a project assessment and get a consultation from an engineer with years of experience in the JavaScript ecosystem. Order a turnkey monorepo setup and see the efficiency of automation.

Backend Development Services: Laravel, Node.js, Go, Django, PostgreSQL

On a production server at 3:14 AM, the Laravel Jobs queue stopped processing. 40,000 unprocessed jobs in Redis. Cause: worker crashed due to a memory leak in one of the Jobs (leak via a static variable in an Eloquent observer), supervisor didn't restart it because of misconfigured stopwaitsecs. This is not a hypothetical scenario — it's Tuesday. We analyzed such an incident on a project with 500 RPS load: diagnosis took 4 hours, fix — 20 minutes. So you don't lose money on downtime, we offer backend development services with a focus on production-grade reliability. We'll assess your project in 2 days.

Backend is what works when no one is watching. Or doesn't work. We guarantee you'll have the first option.

How do we ensure production-grade reliability from day one?

What we do correctly from day one

Service Layer over Fat Controllers. Controller receives HTTP request, validates it via Form Request, passes data to Service, returns response. Business logic in Service, not Controller. This sounds trivial, but most legacy projects have controllers with 500 lines and SQL queries inside.

Repository Pattern we use cautiously. If you just wrap Model::where(...) in a repository method — that's boilerplate without benefit. Repository is justified when: you need to abstract from the data source (DB + cache + external API) or when query logic is complex enough to isolate.

Jobs, Events, Listeners. Everything that can be async — make async. Sending email, PDF generation, external API sync, aggregate recalculation — into Queue. Laravel Horizon for queue monitoring in Redis: see throughput, failed jobs, processing time per queue.

How Octane handles high load

Laravel Octane with RoadRunner or Swoole keeps the app in memory between requests — removes bootstrap overhead (config loading, class autoloading) on each HTTP request. Gain: 3–8x on synthetic benchmarks, 2–4x on real applications. Important: no state between requests in static variables — that leads to exactly the incidents from the beginning. We use this in projects with >1000 RPS.

What to do about N+1 queries

N+1 is the most common cause of slow pages in Laravel apps. Standard story: page worked fine on dev with 10 records, on production with 10,000 — 8-second load.

Laravel Debugbar in dev environment shows the number of queries per page. More than 20 queries per page — signal for audit.

Model::preventLazyLoading(! app()->isProduction());

Telescope for profiling in staging: logs all queries, jobs, mail, notifications with time detail. Numbers: after implementing eager loading, page load time drops from 8s to 0.3s — 27 times faster.

PostgreSQL: indexes that are actually needed

PostgreSQL 14+ is the primary DB on all projects. We use PgBouncer + PostgreSQL combination. 10+ years experience, more than 50 backend projects, 5 years on the market.

How PostgreSQL helps avoid slow queries

Composite indexes for frequent WHERE + ORDER BY. If you have WHERE user_id = ? AND status = ? ORDER BY created_at DESC — you need (user_id, status, created_at DESC). A separate index on (user_id) doesn't help much with sorting.

Partial indexes. If 95% of queries go with WHERE status = 'active':

CREATE INDEX idx_orders_active ON orders (created_at DESC)
WHERE status = 'active';

The index is small, fast, covers the main load.

GIN indexes for JSONB and arrays. @> operator without GIN index — seq scan. With index — fast even on millions of rows.

GIN for full-text search. to_tsvector + GIN instead of LIKE '%query%'. LIKE without index is always seq scan. With pg_trgm extension and gin_trgm_ops — supports LIKE with index, useful for CRM search by partial match.

Connection pooling: why it's more important than it seems

Rails, Laravel, Django open a new connection to PostgreSQL for each PHP/Python process. With 100 workers — 100 connections. PostgreSQL starts degrading from 200–300 active connections — overhead on connection management becomes significant.

PgBouncer — connection pooler in front of PostgreSQL. Transaction pooling mode: connection to PostgreSQL is occupied only during a transaction, returned to pool between requests. 1000 application workers → 20–50 actual connections to PostgreSQL. This reduces latency by 40% and hosting costs by 30%.

Node.js with Fastify: when it's better than Laravel

Node.js is justified for:

  • Realtime: WebSocket servers, Server-Sent Events, chat, live updates
  • Streaming: large files, video, streaming data
  • High I/O concurrency: many parallel requests to external APIs without heavy business logic
  • Serverless: Lambda/Cloud Functions — Node.js starts faster than PHP

Fastify over Express: 2–3 times faster on benchmarks, built-in JSON Schema validation, better TypeScript support, plugin architecture.

Typical realtime architecture: Laravel — core business logic and REST API. Node.js + Socket.io or ws — WebSocket server. Laravel publishes events to Redis Pub/Sub, Node.js subscribes and broadcasts to clients. This separation allows scaling the WebSocket server independently of the main app.

Go: microservices and high load

Go we use for:

  • High-load microservices (>10,000 RPS)
  • Background workers with strict latency requirements
  • DevOps tools and CLI
  • gRPC services in microservice architecture

Goroutines — thousands of times cheaper than OS threads. 10,000 concurrent connections on Go is normal on one server.

But Go is not a silver bullet. Development is slower than Laravel: more boilerplate, no ORM at Eloquent level, error handling with if err != nil everywhere. Justified only when performance is a real requirement, not an assumption.

Django and Python backend

Django with DRF (Django REST Framework) — for tasks where Python is needed: ML pipelines, data processing, integrations with AI tools.

Celery for background tasks — similar to Laravel Queue but more complex to configure. Celery Beat for cron tasks.

Django ORM vs raw SQL: ORM is convenient for CRUD. For analytical queries with multiple JOINs, window functions, and CTEs — connection.execute() with raw SQL is more readable and predictable.

Redis: not just cache

Redis in our projects plays multiple roles:

Role Details
Cache Caching results of heavy queries, HTML fragments
Queues Backend for Laravel Queue / Celery
Session store Distributed sessions in multi-instance environment
Pub/Sub Realtime events between services
Rate limiting Sliding window counters for API throttling
Leaderboards Sorted Sets for rankings

Redis Cluster for horizontal scaling. Sentinel for automatic failover on standalone setups.

Deployment and infrastructure

Docker + docker-compose — standard for local development and production. Each service in a container: PHP-FPM/Octane, Nginx, PostgreSQL, Redis, Queue Worker, Scheduler.

CI/CD via GitHub Actions:

  1. Run tests (PHPUnit / Pest, Vitest, Playwright)
  2. Build Docker image
  3. Push to Container Registry
  4. Deploy: docker pull → docker-compose up -d on server, or Kubernetes rolling update

Zero-downtime deploy for Laravel: php artisan down --secret=TOKEN is not needed with proper configuration. Strategy: new container starts next to the old one, Nginx switches traffic after health check, old container stops.

Monitoring: Sentry for exception tracking with alerting in Slack/Telegram. Grafana + Prometheus (or Grafana Cloud) for metrics: CPU, memory, request rate, queue depth, database connection count. Alerts on: error rate > 1%, p99 latency > 2s, queue depth > 1000 jobs.

What's included in turnkey work

  • Architecture design (API documentation, DB schema, service diagram)
  • Implementation according to agreed specification with code review
  • CI/CD, monitoring, alerting setup
  • Load testing (k6, wrk) with report
  • Handover of source code, access, deployment instructions
  • Training of customer's team (2-3 sessions)
  • Warranty support for 1 month after delivery

Timeline benchmarks

Task Timeline
REST API for mobile/SPA (medium complexity) 6–12 weeks
Backend with complex business logic + integrations 12–20 weeks
High-load service on Go 8–16 weeks
Migration from legacy PHP to Laravel 16–32 weeks

Pricing is calculated individually after analyzing load, integrations, and business logic. Contact us for a free audit of your current backend — get an optimization plan in 2 days. Request a consultation.