Database design and query optimization
Slow queries found and fixed, schemas that hold at the next stage of growth, and backups that have actually been restored.
In short
Database optimization is finding the slow queries behind a slow application and fixing them with evidence: EXPLAIN plans, matching indexes and safe changes to live tables. It is for apps that slow down as tables grow or traffic peaks, on MySQL or PostgreSQL.
Key facts
- Engagement
- fixed-scope project
- Price
- Fixed price for the review, then a quote for larger changes
- Timeline
- Scoped after reading the slow-query logs
- First step
- MeasureSlow-query logs, EXPLAIN plans and application traces show where the time goes.
- Works with
- MySQL
- PostgreSQL
- Redis
- PgBouncer
- Laravel migrations
- Prisma
- Elasticsearch
- Based in
- Mumbai, India · UTC+5:30I plan my working day around my clients' hours. The overlap with your timezone is shown on the contact page.
What it is
What database optimization is
Database design and query optimization is finding the slow queries that make an application slow, fixing them with evidence, and designing schemas that hold at the next stage of growth. I work with MySQL and PostgreSQL, with Redis caching where it helps: slow-query analysis with EXPLAIN plans, indexes that match your real access patterns, safe changes to large live tables, read replicas and connection pooling, and backups proven by restoring them. It is for applications that slow down as tables grow or when traffic peaks, and teams planning a schema change on a table they can't take offline.
Who it is for
Who it is for, and who it is not
Who this is for
- Apps that slow down as tables grow or when traffic peaks
- Teams planning a schema change on a large live table
- Products whose backups have never been restored
Who this is not for
- Data warehousing and BI modelling
- Administering a vendor's managed ERP database
What you get
What you get
- A slow-query report with fixes ranked by impact
- Indexes and query rewrites, deployed and measured
- A plan for schema changes without downtime
- Replication, pooling and backup configuration where needed
- A restore test and a written recovery procedure
Scope
The review comes first and is fixed-price: I read the slow-query logs, the EXPLAIN plans of the worst offenders and the application's own traces, and rank fixes by how much time they save across real traffic, not by how bad a single query looks. Larger changes, a schema redesign, replicas or a migration, are quoted separately after the review.
What is measured and changed
MySQL's slow query log records statements that take longer than a threshold you set, which makes it the natural starting list. EXPLAIN then shows how the database plans to run each one: which indexes it uses, how many rows it expects to read, and where it sorts or scans. Most fixes are unglamorous: an index that matches how the query filters and sorts, a query that loads related rows once instead of once per row, a pagination that doesn't count the whole table, a report moved to a replica. For the Laravel side of the same problem, see Laravel performance in 2026: a production playbook.
Schema changes on large live tables are done online, in steps: add the new column or index without locking writes, backfill in batches, switch reads and writes over, and keep a way back at each step. Connection pooling, with PgBouncer for PostgreSQL, keeps a burst of application instances from exhausting the database's connections.
On the TopGear India rebuild, the slow pages came from slow SQL; rewriting the queries and indexing the tables for how the site actually reads them was part of how the main pages went from 1–3 min → 3 s.
What it is not
It is not data warehousing or BI modelling, and it is not administering a vendor's managed ERP database. It is also not "add more hardware": bigger instances are sometimes right, but only after the review shows the time isn't going into a few fixable queries.
How it works
How the engagement runs
- Step 01
Measure
Slow-query logs, EXPLAIN plans and application traces show where the time goes.
- Step 02
Fix the biggest first
Indexes, query rewrites and caching, ranked by time saved across real traffic.
- Step 03
Change safely
Schema changes applied online, backfilled in batches, with a way back at each step.
- Step 04
Protect
Backups restored for real, replicas and alerts on the numbers that matter.
Technologies I use for this
- MySQL
- PostgreSQL
- Redis
- PgBouncer
- Laravel migrations
- Prisma
- Elasticsearch
How this works in your market
How this works in the United States
For US teams, the review usually runs on a read replica or a recent snapshot, so production isn't touched while I measure. Changes to live tables are scheduled in a window we agree; your morning overlaps my evening, so the riskiest steps happen with both of us at work.
How this works in the European Union
For teams in the European Union, databases hold personal data, so I work inside your infrastructure, on anonymized copies where I need realistic volumes, under a data processing agreement. Most of your working day overlaps mine, which keeps the measure, change and re-measure loop short.
Proof
Case studies behind this service
- Case study: InfluencerX · Real-time voting platform
- users over the campaign
- 1.6M+
- Case study: TopGear India CMS · CMS migration and modernization
- page load time, before → after
- 1–3 min → 3 s
FAQs
Questions about Database design and query optimization
How do you find what's slow?
From evidence: the slow-query log, EXPLAIN plans and the application's own traces, then fixes ranked by how much time they save across real traffic.
Can you change a big table without downtime?
Usually: add columns and indexes online, backfill in batches, switch reads and writes over in steps, and keep a way back at each step.
MySQL or PostgreSQL?
Both. For a new product I lean towards PostgreSQL; for an existing one, the database you already run is usually the right one to tune.
Should we add a cache instead?
Sometimes, and often as well. A cache in front of the reads everyone makes at once protects the database at peak, as it did on the InfluencerX voting platform. But caching a slow query hides it rather than fixing it, so the query comes first.
Do you need production access to the database?
Read access to the slow-query log and a read replica or snapshot is enough for the review. Changes go through your normal deploy process.
How do you prove backups work?
By restoring one into a separate environment, timing it and checking the data, then writing the procedure down so someone else can do it.
How do I find and fix slow queries in MySQL or PostgreSQL?
Work in four steps. First collect the slow queries, from MySQL's slow query log or the application's traces; second, run EXPLAIN on the worst offenders to see which indexes they use and how many rows they read; third, fix the cause with an index that matches how the query filters and sorts, or a rewrite that loads related rows once instead of once per row; fourth, add a cache only after that, because caching a slow query hides it instead of fixing it. Measure again after each change.
What does EXPLAIN tell me?
EXPLAIN shows how the database plans to run a query: which indexes it uses, how many rows it expects to read, and where it sorts or scans. MySQL and PostgreSQL both document the output, and every fix in the review is checked against the plan before and after.
How do I add an index without downtime?
Use the database's online option. PostgreSQL's CREATE INDEX CONCURRENTLY builds an index without taking locks that block inserts, updates or deletes, though it takes longer and can leave an invalid index behind if it fails, which has to be dropped and rebuilt. MySQL's InnoDB adds a secondary index in place, and the table stays available for reads and writes while it is built. Either way, keep a way back at each step, as with any change to a live table.
Sources
Related writing
- Article: Laravel performance in 2026: a production playbook · 2 November 2026
What actually makes Laravel applications fast in production, from queries and caching to queues and Octane.
- Article: TopGear India: moving a publishing CMS from CodeIgniter to Laravel while the newsroom kept publishing · 2 November 2026
The decisions behind one CMS migration: a full rewrite, the content model and URLs kept, the speed found in SQL, caching and images, and an editor-first CMS.
Where this work happens
- Working with teams in United States · New York · Chicago · San Francisco
A senior software engineer for US startups and product teams, working remotely from Mumbai so that the East Coast morning falls inside my evening. It is for founders and CTOs who need senior engineering without a full-time hire: MVPs, AI features, performance work and rescuing apps built in a hurry.
- Working with teams in European Union · Berlin · Amsterdam · Dublin
A freelance software engineer for European teams, working remotely from Mumbai with most of your working day in common. It is for product teams in Germany, the Netherlands, Ireland and the Nordics that need senior engineering, including the work behind GDPR, the Accessibility Act and the AI Act.