Living in T̶o̶x̶i̶c̶ Environments

Have you ever faced a problem where your code works fine on your computer but after deploying it, your code suddenly contains bugs that never come while testing in your local environment? Each machine can have different environment based on many things, if it works on your local machine it doesn’t guarantee to work on other machines.

What is Environment?

An environment is the context in which code is executing. This includes all code executables and variables available to the code being executed. You can think of an environment as a unique machine executing code. Each machine is a different environment. Environment is used in other ways to express a type of configuration, such as a networking environment, database environment, transaction processing environment, batch environment, interactive environment and so on.

Why is there a need?

Why do we need different places to deploy our code to. Now imagine you work for a bank, and want to test a feature where a customer can withdraw Rp10.000.000 from their account.

You seriously don’t want your developers to withdraw money every time they load up the App. Actually, you don’t even want to do it once. What we want is to have some sort of development environment where you can (in this case) withdraw money without it changing the balance of real customers.

Multiple environments allow the developer or QA team to have private application. We want to see if our code has fulfilled the expected outcome, but we want any issues or debugging logs to be visible only to us and not to the real users.

The Environments

Development

Here we generally would want some logging for developers to see what isn’t working correctly. You don’t (usually) want development environments to use the same database, logging or analytics systems as a production environment.

· Usually uses test databases

· API calls may be directed to a test backend

· Debug symbols may be turned on, which makes applications run slower than in production

· Analytics disabled

· Push actions from a server (websockets, mobile notifications, Forced updates) only apply to DEV software

Staging

Usually used for human testing (although dev may be used for this purpose).

The idea is that the environment is similar to Development in that the system uses test databases, but is also similar to Prod in that the speed of the execution should be the same as the production version.

· Uses test databases

· Most of the environment is the same as Prod

Production

In production everything is “real”, or at least should be as this is the environment that your users are going to use. However, when you use a Prod app and (for example) charge a credit card, that credit card will be charged. That is, be careful.

· Uses real databases

· No debugging

How do we set up our environment in PPL

In our PPL Project, we have 3 environments that are development, staging, and production. Development is running on our local computer from each developer. Staging and Production run on the same server but different port. Here is some environments variable that we use in our product.

On Backend

DB_USERNAME=
DB_PASSWORD=
DB_HOST=
DB_PORT=
DB_NAME=
PORT=
FORWARD_PORT=
GIN_MODE=
GOOGLE_APPLICATION_CREDENTIALS=
SERVER_PATH_GOOGLE_APPLICATION_CREDENTIALS=
GCS_PROJECT_ID=
GCS_BUCKET_NAME=
GCS_UPLOAD_PATH=
TALENTA_HMAC_USERNAME=
TALENTA_HMAC_SECRET=

JWT_PRIVATE_KEY=
WHITELISTED_EMAIL_DOMAINS=

GOOGLE_OAUTH_CLIENT_ID=

On Frontend

NEXT_PUBLIC_API_URL=
NEXT_PUBLIC_APP_ENV=
NEXTAUTH_URL=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

Each environment has different dependencies like database, URL, etc. So that we need different variables for each environment so we don’t infer the other environment or application.

Final Words

So in the conclusion, each environment has its own variable and different place from each other. It has different functions to test is our application works well or not. Here is the summary of our environment terminology:

  • Production Environment: The environment used by the end user of your software
  • Development Environment: The environment you use when you create software
  • Environment: The Operating System, API calls and databases used by software
  • Staging Environment: An environment somewhere between Development and Production

Thanks for reading and don’t forget to be grateful!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ageng Anugrah Wardoyo Putra

Ageng Anugrah Wardoyo Putra

Just an ordinary human who has many dreams that haven’t come true.