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.
Schema design and query tuning for MySQL and PostgreSQL, with Redis caching where it helps: slow-query analysis with EXPLAIN plans, indexes that match your real access patterns, safe migrations on live tables, read replicas and connection pooling, and backups tested by restoring them.
- 01
A slow-query report with fixes ranked by impact
- 02
Indexes and query rewrites, deployed and measured
- 03
A plan for schema changes without downtime
- 04
Replication, pooling and backup configuration where needed
- 05
A restore test and a written recovery procedure
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 this service 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.
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.
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 the engagement runs
Measure
Slow-query logs, EXPLAIN plans and application traces show where the time goes.
Fix the biggest first
Indexes, query rewrites and caching, ranked by time saved across real traffic.
Change safely
Schema changes applied online, backfilled in batches, with a way back at each step.
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.
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?
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.
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
Related writing
- Article: Laravel performance in 2026: a production playbook · 10 October 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 · 11 October 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
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
Product teams in Germany, the Netherlands, Ireland and the Nordics, including the engineering behind GDPR, the Accessibility Act and the AI Act.