











{"author":"Faiq Najib Al-Aziz","body":"\nThe PHP codebase I worked on had become hard to maintain. New features were harder to add, bugs showed up more often, and every deploy felt like flipping a coin. PHP itself wasn't the culprit. The system had grown for years without a clear architecture. One day I had to roll back three times after a deploy that should have been simple. That was a stressful afternoon.\n\nI'm not here to argue that \"_Go is better than PHP_\" or \"_PHP is dead_.\" This is my account of migrating a backend system from PHP (CodeIgniter 3 and Laravel) to Go. It's not a tutorial, and definitely not a call for everyone to switch languages. Maybe my experience, mistakes included, will help someone dealing with something similar.\n\n## What Made It Hard: The Architecture\n\nThe system I handled looked like this:\n\n- **370+ API endpoints**[^1]\n- **33 database entities with complex relationships**\n- **~194,000 lines** of PHP code across CodeIgniter 3 and Laravel\n- Testing existed, but coverage was very low.\n\nPHP wasn't the problem by itself. PHP is perfectly usable. The trouble spots in this system were:\n\n1. **No layer separation**: controllers queried the database directly, and business logic was mixed with presentation logic. Like fried rice with everything mixed in, it was hard to tell where one concern ended and another began.\n2. **Hard to test**: tightly coupled code made unit testing difficult. To test one function, I had to set up a database, mock three dependencies, and hope it worked.\n3. **Declining developer experience**: onboarding new developers took longer, and bug fixes carried more risk. One new developer said, _\"So... this is an... interesting architecture.\"_ In other words, chaotic.\n\nSo changing languages alone wasn't going to be enough. The architecture needed work too.\n\n## Why I Picked Go\n\nIf you ask why I didn't just refactor in PHP, the answer is: **I could have**. For this project, Go felt like a better fit for a few reasons. Not just because people were talking about it.\n\n### 1. Type Safety Saves Debug Time\n\nPHP is dynamically typed[^2], so many bugs only surface at runtime. Go's static typing can catch type-related errors at compile time, before they reach production.\n\n### 2. Goroutines Helped with Concurrency\n\nThis system handles many simultaneous requests, from real-time GPS tracking to report generation. Compared with other approaches I've tried, goroutines make concurrent programming much simpler. The first time I used them, I thought, _\"Wait, it's really this simple?\"_\n\n### 3. A Simpler Deploy\n\nGo produces one binary. There is no `composer install` on the server and no PHP version conflict to worry about. PHP deployments meant checking that composer dependencies were installed, the PHP version matched, and the required extensions were available. Now I build locally and use `scp` to send one file.\n\n### 4. More Predictable Resource Use\n\nI wasn't focused on benchmark numbers, but on **predictable resource usage**. Go's consistent memory usage makes capacity planning easier. The old PHP system could have unexplained memory spikes. Now memory usage is flatter and more predictable.\n\nGo isn't perfect. Its error handling is verbose (all those `if err != nil`)[^3], and its ecosystem is smaller than PHP's. For this use case, the trade-offs were worth it.\n\n## How I Migrated: Module by Module\n\nOne migration risk is deciding to rewrite everything at once. I once heard about a team that spent two years on a big-bang rewrite and never finished. Burnout, scope creep, changing business requirements, you name it. Projects can wander off in plenty of ways.\n\nThe approach I used:\n\n### 1. Module Mapping\n\nFirst, I mapped all endpoints and entities to clear modules. I grouped the 370+ endpoints into domains such as authentication, tracking, reporting, and user management. Building a spreadsheet to map them took a few days. It was tedious, but it helped with the work that followed.\n\n### 2. Service-Repository Pattern\n\nI designed each module using the **service-repository** pattern:\n\n- **Repository layer**: responsible for data access (database queries)\n- **Service layer**: contains business logic, calls the repository\n\nThat separation helped with a few things:\n\n- Repositories can be mocked when testing services\n- Business logic can be tested without a database\n- Adding features doesn't break other parts\n\nWith clear layers, each part has its own job. The pattern felt like over-engineering at first. After a few months of using it, I could see the point.\n\n### 3. One Endpoint at a Time\n\nThe process was roughly:\n\n1. Take one endpoint from PHP\n2. Write test cases based on existing behavior[^4]\n3. Implement in Go using the service-repository pattern\n4. Test until passing\n5. Deploy and monitor\n6. Repeat\n\nThe process is slow, but **predictable**. Each migrated endpoint is measurable progress that stakeholders can see. _\"This week we migrated 5 endpoints\"_ is clearer than saying _\"we're still working on the migration\"_ for months without visible results.\n\n## What Changed\n\nA few numbers from the project:\n\n- **370+ endpoints** successfully migrated\n- **33 entities** converted from MySQL to PostgreSQL[^5]\n- **194K+ lines** of PHP transformed into a cleaner Go architecture\n- **More consistent response times**: no more unexpected spikes\n- **Test coverage rose from almost nothing**\n- **Faster developer onboarding**: clear code structure lets new developers contribute sooner\n\nOne benefit that doesn't show up in the numbers is a calmer deployment process. I no longer go into a deploy hoping nothing breaks. It can still be nerve-wracking, but it doesn't keep me up at night.\n\n## Things I Learned Along the Way\n\nI came away with a few lessons:\n\n### Get to Know the Old System First\n\nBefore writing Go, I spent time learning how the existing system behaved. I read the code and tried to figure out **why** certain decisions had been made. Code that looks \"weird\" might have made sense in its original context. So I try not to call legacy code bad too quickly. There may be a constraint I can no longer see.\n\n### Don't Rewrite Everything at Once\n\n_If you can do it in pieces, why do it all at once?_ Incremental work feels slower, but it carries less risk. You can show stakeholders each finished endpoint, and the existing system keeps running.\n\n### Test Before Moving Things Over\n\nWriting tests for a legacy system can be tedious (I know). But tests are a safety net against quietly changing behavior after migration. Without them, you might change something users already rely on.\n\n### Don't Make It Complicated Too Soon\n\nI was tempted to jump into microservices, message queues, and all sorts of elaborate architecture. But a system without a stable architecture needs a foundation first, not more moving parts. A well-structured monolith is easier to live with than chaotic microservices. KISS (_Keep It Simple, Stupid_)[^6] still comes in handy.\n\n## So, Should You Move to Go?\n\nFor me, moving from PHP to Go isn't a contest over which language is better. It's about **choosing a tool that fits the problem**. In this project, Go's static typing, concurrency model, and simpler deployment made sense.\n\nDoes every PHP system need to move to Go? _Nope_. If your system runs well, the architecture is clear, and the team is comfortable with PHP, switching just because it is trendy will only create more work. I think migration makes sense when the business value is clear and the benefits can be measured.\n\nIf the legacy system you work on is becoming difficult to maintain and you'd like to discuss a migration approach, [get in touch](/en/contact/). You can also learn more about my [services](/en/services/).\n\n[^1]: I seriously double-checked that number the first time I counted. Turns out, yes, that many hahaha.\n\n[^2]: PHP 7+ does have type hints and strict types, but it's still not as strict as Go which is statically typed from the ground up.\n\n[^3]: In the early days of using Go, I was genuinely annoyed by all the `if err != nil`. But after getting used to it, you just accept it. Besides, verbose but clear beats concise but hidden error handling any day.\n\n[^4]: Writing tests based on existing behavior is important. The last thing you want is the migration accidentally changing behavior that users already depend on.\n\n[^5]: The MySQL to PostgreSQL migration is a whole story on its own. Maybe I'll write about it someday hehe.\n\n[^6]: Keep It Simple, Stupid, a principle that often gets forgotten when we get too excited about new technology.\n\n---\n\n_Tags: [go](/en/tags/go/) · [php](/en/tags/php/) · [architecture](/en/tags/architecture/) · [migration](/en/tags/migration/)_\n","body_clean":"The PHP codebase I worked on had become hard to maintain. New features were harder to add, bugs showed up more often, and every deploy felt like flipping a coin. PHP itself wasn\u0026rsquo;t the culprit. The system had grown for years without a clear architecture. One day I had to roll back three times after a deploy that should have been simple. That was a stressful afternoon.\nI\u0026rsquo;m not here to argue that \u0026ldquo;Go is better than PHP\u0026rdquo; or \u0026ldquo;PHP is dead.\u0026rdquo; This is my account of migrating a backend system from PHP (CodeIgniter 3 and Laravel) to Go. It\u0026rsquo;s not a tutorial, and definitely not a call for everyone to switch languages. Maybe my experience, mistakes included, will help someone dealing with something similar.\nWhat Made It Hard: The Architecture #The system I handled looked like this:\n370+ API endpoints1 33 database entities with complex relationships ~194,000 lines of PHP code across CodeIgniter 3 and Laravel Testing existed, but coverage was very low. PHP wasn\u0026rsquo;t the problem by itself. PHP is perfectly usable. The trouble spots in this system were:\nNo layer separation: controllers queried the database directly, and business logic was mixed with presentation logic. Like fried rice with everything mixed in, it was hard to tell where one concern ended and another began. Hard to test: tightly coupled code made unit testing difficult. To test one function, I had to set up a database, mock three dependencies, and hope it worked. Declining developer experience: onboarding new developers took longer, and bug fixes carried more risk. One new developer said, \u0026ldquo;So\u0026hellip; this is an\u0026hellip; interesting architecture.\u0026rdquo; In other words, chaotic. So changing languages alone wasn\u0026rsquo;t going to be enough. The architecture needed work too.\nWhy I Picked Go #If you ask why I didn\u0026rsquo;t just refactor in PHP, the answer is: I could have. For this project, Go felt like a better fit for a few reasons. Not just because people were talking about it.\n1. Type Safety Saves Debug Time #PHP is dynamically typed2, so many bugs only surface at runtime. Go\u0026rsquo;s static typing can catch type-related errors at compile time, before they reach production.\n2. Goroutines Helped with Concurrency #This system handles many simultaneous requests, from real-time GPS tracking to report generation. Compared with other approaches I\u0026rsquo;ve tried, goroutines make concurrent programming much simpler. The first time I used them, I thought, \u0026ldquo;Wait, it\u0026rsquo;s really this simple?\u0026rdquo;\n3. A Simpler Deploy #Go produces one binary. There is no composer install on the server and no PHP version conflict to worry about. PHP deployments meant checking that composer dependencies were installed, the PHP version matched, and the required extensions were available. Now I build locally and use scp to send one file.\n4. More Predictable Resource Use #I wasn\u0026rsquo;t focused on benchmark numbers, but on predictable resource usage. Go\u0026rsquo;s consistent memory usage makes capacity planning easier. The old PHP system could have unexplained memory spikes. Now memory usage is flatter and more predictable.\nGo isn\u0026rsquo;t perfect. Its error handling is verbose (all those if err != nil)3, and its ecosystem is smaller than PHP\u0026rsquo;s. For this use case, the trade-offs were worth it.\nHow I Migrated: Module by Module #One migration risk is deciding to rewrite everything at once. I once heard about a team that spent two years on a big-bang rewrite and never finished. Burnout, scope creep, changing business requirements, you name it. Projects can wander off in plenty of ways.\nThe approach I used:\n1. Module Mapping #First, I mapped all endpoints and entities to clear modules. I grouped the 370+ endpoints into domains such as authentication, tracking, reporting, and user management. Building a spreadsheet to map them took a few days. It was tedious, but it helped with the work that followed.\n2. Service-Repository Pattern #I designed each module using the service-repository pattern:\nRepository layer: responsible for data access (database queries) Service layer: contains business logic, calls the repository That separation helped with a few things:\nRepositories can be mocked when testing services Business logic can be tested without a database Adding features doesn\u0026rsquo;t break other parts With clear layers, each part has its own job. The pattern felt like over-engineering at first. After a few months of using it, I could see the point.\n3. One Endpoint at a Time #The process was roughly:\nTake one endpoint from PHP Write test cases based on existing behavior4 Implement in Go using the service-repository pattern Test until passing Deploy and monitor Repeat The process is slow, but predictable. Each migrated endpoint is measurable progress that stakeholders can see. \u0026ldquo;This week we migrated 5 endpoints\u0026rdquo; is clearer than saying \u0026ldquo;we\u0026rsquo;re still working on the migration\u0026rdquo; for months without visible results.\nWhat Changed #A few numbers from the project:\n370+ endpoints successfully migrated 33 entities converted from MySQL to PostgreSQL5 194K+ lines of PHP transformed into a cleaner Go architecture More consistent response times: no more unexpected spikes Test coverage rose from almost nothing Faster developer onboarding: clear code structure lets new developers contribute sooner One benefit that doesn\u0026rsquo;t show up in the numbers is a calmer deployment process. I no longer go into a deploy hoping nothing breaks. It can still be nerve-wracking, but it doesn\u0026rsquo;t keep me up at night.\nThings I Learned Along the Way #I came away with a few lessons:\nGet to Know the Old System First #Before writing Go, I spent time learning how the existing system behaved. I read the code and tried to figure out why certain decisions had been made. Code that looks \u0026ldquo;weird\u0026rdquo; might have made sense in its original context. So I try not to call legacy code bad too quickly. There may be a constraint I can no longer see.\nDon\u0026rsquo;t Rewrite Everything at Once #If you can do it in pieces, why do it all at once? Incremental work feels slower, but it carries less risk. You can show stakeholders each finished endpoint, and the existing system keeps running.\nTest Before Moving Things Over #Writing tests for a legacy system can be tedious (I know). But tests are a safety net against quietly changing behavior after migration. Without them, you might change something users already rely on.\nDon\u0026rsquo;t Make It Complicated Too Soon #I was tempted to jump into microservices, message queues, and all sorts of elaborate architecture. But a system without a stable architecture needs a foundation first, not more moving parts. A well-structured monolith is easier to live with than chaotic microservices. KISS (Keep It Simple, Stupid)6 still comes in handy.\nSo, Should You Move to Go? #For me, moving from PHP to Go isn\u0026rsquo;t a contest over which language is better. It\u0026rsquo;s about choosing a tool that fits the problem. In this project, Go\u0026rsquo;s static typing, concurrency model, and simpler deployment made sense.\nDoes every PHP system need to move to Go? Nope. If your system runs well, the architecture is clear, and the team is comfortable with PHP, switching just because it is trendy will only create more work. I think migration makes sense when the business value is clear and the benefits can be measured.\nIf the legacy system you work on is becoming difficult to maintain and you\u0026rsquo;d like to discuss a migration approach, get in touch. You can also learn more about my services.\nTags: go · php · architecture · migration\nI seriously double-checked that number the first time I counted. Turns out, yes, that many hahaha.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\nPHP 7+ does have type hints and strict types, but it\u0026rsquo;s still not as strict as Go which is statically typed from the ground up.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\nIn the early days of using Go, I was genuinely annoyed by all the if err != nil. But after getting used to it, you just accept it. Besides, verbose but clear beats concise but hidden error handling any day.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\nWriting tests based on existing behavior is important. The last thing you want is the migration accidentally changing behavior that users already depend on.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\nThe MySQL to PostgreSQL migration is a whole story on its own. Maybe I\u0026rsquo;ll write about it someday hehe.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\nKeep It Simple, Stupid, a principle that often gets forgotten when we get too excited about new technology.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\n","canonical":"https://najib.id/en/writing/2026/legacy-php-to-go-migration/","description":"My story of migrating a PHP backend (CodeIgniter 3 and Laravel) to Go, one endpoint at a time.","language":"en","lastmod":"2026-11-11T23:31:00Z","publishedAt":"2026-04-04T00:00:00Z","readingTime":7,"section":"writing","series":null,"tags":["go","php","architecture","migration"],"title":"Migrating Legacy PHP to Go: Why, How, and Lessons Learned","type":"writing","url":"https://najib.id/en/writing/2026/legacy-php-to-go-migration/","wordCount":1368}
