TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Should front end developer run API locally or use shared staging env?

5 pointsby ilmiontabout 4 years ago
We have cleanly split projects where a React SPA communicates with a PHP API.<p>The React developers need to be able to connect to an instance of the API in order to test their work.<p>Would you prefer running the API locally, or using a shared staging instance?<p>The backend is already containerised so developers could spin it up with Docker reasonably easily (there are usually multiple environment variables which would need to be set). My concern with asking frontend devs to run the API locally is it will increase friction when changes to the backend are made. The frontend team would need to be instructed to &quot;pull the changes&quot;&#x2F;&quot;spin up new image&quot;. In addition, changes to the database schema would need to be communicated, and it would be hard to provide a unified set of test data.<p>A shared staging environment (&quot;dev.project.company.com&quot;) alleviates these concerns. The backend team deploys to staging, updates the database schema on the staging DB, and seeds any useful test data. The frontend team doesn&#x27;t need to do anything to &quot;receive&quot; these changes. However, they&#x27;re now dependent on having an internet connection (developers work remotely). It also removes the ability for frontend devs to work against in-development API branches - unless it&#x27;s merged into staging, it&#x27;s not accessible.<p>There&#x27;s tradeoffs on both sides. I&#x27;m leaning towards requiring frontend devs to run the API locally, but am conscious this will increase onboarding time and potentially introduce friction as developers will need to remember to pull changes and apply schema migrations&#x2F;seeds to a local database instance.<p>I&#x27;ve tried to find case studies from other small teams but there seems to be very little writing on how this problem is usually solved, to my surprise. Thoughts welcome.

4 comments

sbacicabout 4 years ago
As a front-end dev, 3 things matter to me:<p>Can I trash the database without affecting the rest of the team?<p>Can I work on branches other than staging&#x2F;prod (in case staging&#x2F;prod is down or there is a bug)?<p>Can I perform common tasks (starting it up, querying the API, testing against it, etc..) without feeling like I&#x27;m pulling teeth?<p>If the answer is yes to all of them, I think the rest of the discussion becomes moot as it won&#x27;t matter where the API is hosted.<p>One idea I&#x27;m currently toying with is having a completely automated build process for the API - ie, you call something like &quot;docker-compose up&quot; and it fetches the newest stable version of the API, migrates the database and sets up everything with sane defaults.
monoideismabout 4 years ago
Most companies use remote dev APIs. You can have a versioned staging&#x2F;production and then a dev API under continuous deployment is ideal, imho. This is an area where CI&#x2F;CD shines.<p>A small company may run them locally as docker instance, but I think it&#x27;s suboptimal and lots of unneeded overhead as you point out. If a frontend dev really needs to be offline, they can always switch to a docker instance (I haven&#x27;t always had that option) but it&#x27;s probably wise to normally use a remote dev API.
matheistabout 4 years ago
How do the backend devs test changes to the API and to the DB schema? Are they not running versions locally themselves? Can the frontend devs just do whatever the backend devs do?<p>&gt; <i>The frontend team would need to be instructed to &quot;pull the changes&quot;&#x2F;&quot;spin up new image&quot;.</i><p>With a small investment in tooling you can probably get away without asking too much of frontend devs.<p>Write your &quot;launch local api&quot; script (checked into the frontend repository) to just work without taking any parameters: put the latest docker image tag into version control. If you have a `latest` tag for your image then you don&#x27;t even need to update the frontend repo, instead you can just always pull the image as part of the launch script. Anyone working on an API dev branch can just replace the image tag (either in the script, or you can provide a flag to override it).<p>Write your launch script to also start up the database if it&#x27;s not running. You can check at API startup whether the db version matches the API, and inform the dev if there&#x27;s a mismatch.
joshxyzabout 4 years ago
&gt; However, they&#x27;re now dependent on having an internet connection (developers work remotely).<p>Internet is a necessity anyways, they better have it and the company better cover it.<p>&gt; It also removes the ability for frontend devs to work against in-development API branches - unless it&#x27;s merged into staging, it&#x27;s not accessible.<p>Can try 3 environments. Dev, Staging, and Prod. An advantage on centralizing these environments is your frontend devs dont worry anymore if their local api version is outdated.