Code is Science is back: the journal code policy tracker now covers 24 journals.See the tracker

Cloud computing for research: moving lab code to the cloud without surprises

When renting compute beats your laptop or the campus cluster, and how to package code, store data, cap the bill and keep results reproducible.

PracticeBy the Code is Science editorsNov 24, 202610 min read
Line illustration of a laptop on a lab bench connected by a cable to a cloud holding server racks and a stack of data disks, with a microscope and an open notebook
Key takeaways
  • Use the cloud for bursts, GPUs and shared data; steady large workloads usually belong on HPC.
  • Measure your code locally, make it run headless, and package it in a pinned container first.
  • Keep raw data read-only in object storage, in the same region as the compute.
  • Set budget alerts and tags before the first job, and write a run manifest for every result.

Cloud computing for research means renting compute, storage and managed services from a provider such as Amazon Web Services, Google Cloud or Microsoft Azure instead of running them on a laptop or a campus cluster. In short: use the cloud when your work comes in bursts, needs hardware you do not own, or has to sit next to a large dataset; package the code in a container first, keep data in object storage, set a budget alert before the first run, and record exactly which machine and image produced each result.

The appeal is easy to see. The Internet2 CLASS course describes an ecologist facing 158.6 TB of satellite imagery that would have taken a departmental server about 48 days to process; rented machines working in parallel can finish it far sooner. The catch is just as real. The Software Sustainability Institute's guide to using cloud in research warns that a move to the cloud brings work that has nothing to do with your research question, and it advises setting limits on that effort before you start.

Most groups handle this work themselves, with a campus research computing team, or with outside help. When a project grows from a few batch jobs into a hosted pipeline that other labs depend on, some hire a firm offering cloud software development services to build the infrastructure, while the scientists keep the analysis, the validation and the decisions about data. The steps below apply in each case.

What does cloud computing offer a research group?

The cloud offers capacity on demand: you pay for machines, storage and services by the hour or by the gigabyte, and you release them when the job ends. That suits work that comes in peaks, such as a reanalysis before a revision deadline, a parameter sweep, or a week of GPU training.

It is one option among several; the right one depends on the shape of the work.

OptionBest forMain limits
Laptop or lab workstationDevelopment, small datasets, teachingMemory, run time, one person's machine
Campus or national HPCLarge, steady batch workloads; MPI jobsQueues, fixed software stack, allocation rounds
Commercial cloudBursts, GPUs on demand, hosted services, shared dataPay-per-use bills, setup effort, data transfer fees
Funded cloud programmesLearning and pilots (for example NIH Cloud Lab)Time-limited credits, eligibility rules

A hybrid pattern works for many labs: develop and test on owned hardware, then send the final, well-understood runs to the cloud. That way a failed experiment costs you an afternoon, not a bill.

When is the cloud the wrong choice?

The cloud is the wrong choice when your workload is large and steady and a free or cheap allocation already exists. A cluster you can use at no direct cost will usually beat paying by the hour for jobs that run all year.

Watch for these other warning signs:

  • Data you are not allowed to move. Some data use agreements and ethics approvals name specific storage locations. Check them before uploading anything.
  • Software licences tied to hardware. Commercial packages may forbid cloud use or charge more for it. The SSI guide lists licence checks as a step of its own.
  • Tightly coupled parallel jobs. Codes that need fast interconnects between many nodes often run better on HPC than on general-purpose cloud machines.
  • No one to own it. An account left running after a student graduates keeps billing. If nobody will own the account, wait.

How do you check whether your code is ready for the cloud?

Measure what the code needs on a machine you already have. The SSI guide starts with the same step: know the CPU, memory, disk and network demands of your application before you choose a provider or an instance type.

  1. Time a representative run. Record wall time, peak memory and the size of inputs and outputs. On Linux, /usr/bin/time -v gives most of this in one line.
  2. List every dependency. Language versions, libraries, system packages, reference files and licence servers. Anything that only exists on your laptop will break first.
  3. Remove hard-coded paths. Read input and output locations from arguments or a config file, so the same script runs locally and on a rented machine.
  4. Make it run headless. No interactive prompts, no notebook cells run by hand. A single command should go from raw input to results.
  5. Port in stages. Run one sample on one machine, then ten, then the full set. Each step tells you where a new failure came from.

How do you package research code so it runs the same in the cloud?

Package it in a container built from a pinned environment. A container image carries the operating system libraries, the language runtime and your exact package versions, so the run on a rented machine matches the run on your desk. Our guide to reproducible environments covers lockfiles and container files step by step.

Containers also help people, not only servers. The Bennett Institute at Oxford describes building development containers and running them in GitHub Codespaces, so researchers open a fully configured environment in the browser instead of spending days installing Python, Docker and project tools. The same container definition can then drive batch jobs in the cloud.

Two habits keep this honest. Tag every image with the git commit it was built from, and store the image in a registry rather than rebuilding it from scratch for each run, because an unpinned rebuild months later can pull different package versions.

Where should research data live in the cloud?

Large research data should live in object storage, with compute brought to it. Object stores such as Amazon S3, Google Cloud Storage and Azure Blob Storage are cheaper per gigabyte than disks attached to virtual machines and survive after the machines are deleted.

  • Bring compute to the data. Run analysis in the same region as the bucket. Moving terabytes back to a laptop is slow and usually billed as data transfer out.
  • Treat raw data as read-only. Write results to a separate prefix or bucket. Turn on versioning or object lock for raw inputs, so a buggy script cannot overwrite them.
  • Use storage classes. Move files nobody reads to colder, cheaper tiers, and check retrieval fees before you archive something you may need next month.
  • Keep a copy outside one provider. The SSI guide recommends a backup strategy and an exit plan before you commit data or applications to a single platform.

Public reference datasets are often already hosted by the providers' open data programmes. Reading them in place can save both transfer time and storage cost.

How do you keep cloud costs under control?

Set a budget alert before the first job, tag every resource with a project name, and shut down anything idle. Most surprise bills come from things left running, not from the experiment itself.

Cost leverWhat to do
Budget alertsCreate an alert at 50%, 80% and 100% of the monthly budget, sent to at least two people.
Tags or labelsTag each machine, disk and bucket with project and owner, so the bill can be split by grant.
Auto-shutdownStop notebook servers and VMs after a period of inactivity; delete disks you no longer need.
Spot or preemptible machinesUse them for jobs that can restart; they cost far less but can be reclaimed at short notice.
Right-sizingPick the instance type from your measured memory and CPU needs, not from the largest option.
Data transferKeep compute and data in one region; download summaries, not raw files.

Free credits help you learn without risk. NIH Cloud Lab, part of the NIH STRIDES Initiative, gives eligible NIH-affiliated researchers up to 90 days of access to a cloud account with $500 of credits on AWS, Google Cloud or Azure, with no prior experience required. The large providers also run their own research credit programmes; check the current terms on their sites.

How do you budget cloud costs in a grant?

Budget cloud as a consumable cost and estimate storage and data transfer as carefully as compute. The SSI guide on funding cloud use argues that proposals should be allowed to treat cloud usage as an eligible consumable cost, and that applicants should show they have considered ongoing storage and transfer charges.

  1. Price a representative run from your measurements, then multiply by the number of runs, plus a margin for failed and repeated jobs.
  2. Add storage for the whole grant and for the period after it, if data must stay available for a journal or a repository.
  3. Add people. Someone has to build and maintain the setup; our article on funding research software explains how to justify that time.
  4. Write the plan down in a software management plan, including who owns the account and what happens to it when the grant ends.

How do you protect sensitive research data in the cloud?

Start from your data agreement and ethics approval, then apply least privilege. Cloud platforms can meet strict requirements, but only when they are configured to do so.

  • Pick the region deliberately. Some agreements require data to stay in a country or jurisdiction.
  • Give each person their own login with only the permissions they need, and turn on multi-factor authentication. Never share a root account.
  • Keep keys out of code. Access keys committed to a public repository can be found by automated scanners quickly. Use the provider's secret manager or short-lived credentials.
  • Block public access on buckets by default, and review sharing settings before publishing anything.
  • Ask your institution first. Many universities have negotiated agreements with providers and a research computing team that has already solved the compliance questions.

How do you keep cloud results reproducible and citable?

Record the exact image, machine type, region and input versions for each run, and define the infrastructure as code. A result that depends on a console setting nobody wrote down cannot be reproduced.

  • Infrastructure as code. Tools such as Terraform or the providers' own templates describe machines, buckets and permissions in files you keep under version control next to the analysis.
  • A run manifest. Write a small file for each run with the container tag, git commit, instance type, region, start time and input checksums, and store it with the outputs.
  • Archive what matters. When you publish, archive the code with a DOI, including the container definition and infrastructure files, so readers can rebuild the setup even if your account is gone.

Cloud services change their interfaces and retire machine types. The archived definition is what lets another group rerun your analysis in five years.

When does a cloud project need engineering help?

A cloud project needs engineering help when it stops being a set of batch jobs and becomes a service. A researcher who follows the steps above can run analyses on rented machines without a specialist. The work changes when:

  • Other groups depend on it. A hosted pipeline or data portal used by other labs needs uptime, monitoring, user accounts and support.
  • Data arrive continuously. Instruments, sensors or apps streaming data into the cloud need ingestion, queues and alerting.
  • Costs reach real money. Once the monthly bill is a meaningful share of a grant, architecture choices pay for themselves.
  • Compliance applies. Clinical or personal data bring audits, logging and access reviews.

Options include a campus research software engineering team, a research software engineer funded on the grant, or an outside firm. If the result is a web platform for a research community, our guide to building a science gateway covers the next steps.

Checklist before your first cloud run

  1. Data agreement and ethics approval checked for storage location and provider.
  2. Budget alert set and sent to at least two people; resources tagged by project.
  3. Code runs headless from one command, with paths read from config.
  4. Container image built from a lockfile and tagged with the git commit.
  5. Raw data in object storage, read-only, in the same region as compute.
  6. Personal logins with multi-factor authentication; no keys in the repository.
  7. One sample run end to end, with a run manifest saved next to the output.
  8. Auto-shutdown on notebooks and VMs; a named owner for the account after the grant.

Most of this is an afternoon of setup before the first job.

Questions about cloud computing for research

Is cloud computing cheaper than a university HPC cluster?

Usually not for large, steady workloads, because campus or national HPC allocations are often free at the point of use. The cloud tends to win for short bursts, GPUs you cannot get locally, hosted services and data shared with other groups. Measure a representative run and price both options before deciding.

Do I need to learn Docker to run research code in the cloud?

It helps a lot. A container built from a pinned environment makes the cloud run match your local run. You can start with a simple container file and a lockfile; many research computing teams offer templates and training.

How do I avoid a surprise cloud bill?

Set budget alerts before the first job, tag every resource with a project and owner, turn on auto-shutdown for notebooks and virtual machines, and delete disks and snapshots you no longer need. Most surprise bills come from resources left running.

Can I put sensitive or clinical data in the cloud?

Often yes, but only if your data use agreement and ethics approval allow it and the account is configured accordingly: an approved region, personal logins with multi-factor authentication, least-privilege access and no public buckets. Ask your institution, which may already have an agreement with a provider.

What should happen to cloud resources when a grant ends?

Plan it before the grant starts. Deposit data that must stay available in a repository, archive the code, container definition and infrastructure files with a DOI, then delete the machines, disks and buckets you no longer need. Name who owns the account afterwards, so nothing keeps billing unnoticed.

Keep reading. More from the desk.