Building and deploying an API for Fundment using FastAPI and GCP

Who are Fundment?

Fundment are a fintech company for financial advisers and their clients. Using proprietary techonology, their platform provides an enhanced digital investment experience for its users, allowing them to automate, streamline, and modernise their investment activities and administration.

Why Lambert Labs?

Fundment came to Lambert Labs having already worked with us on an automated testing project for one of their web apps. Lambert Labs’ deep and wide-ranging knowledge of the Python language and ecosystem, together with our strong expertise in cloud computing (Google Cloud Platform), made us a natural choice.

What did we do?

The main focus of our work was a large backend API powering several of the company’s applications and systems.

Tasked with a complete rewrite of the original Hug API, we created over a hundred endpoints from scratch using FastAPI (adding both new and replacing existing functionality). The new API was RESTful and followed the OpenAPI specification.

Technical highlights of the new API were:

  • Rigourous, well structured and documented schemas using Pydantic
  • Efficient and Pythonic database querying using SQLAlchemy
  • Modular, well designed, secure, and easy to maintain code via FastAPI features, e.g. routers, dependency injection
  • Automatically generated and interactive Swagger API documentation
  • Automatically generated client libraries, e.g. Python, TypeScript, using the OpenAPI CLI generator in GitLab CI/CD
  • Unit, integration (end to end API endpoint tests), and functional (database functions) testing (Pytest) with high test coverage (over 500 tests)
  • Lean and fast local developer environment (Docker Compose + conda)
  • Load testing (Locust) to ensure the API scaled to handling thousands of requests per second in a timely and reliable fashion
  • Authentication – implemented an OAuth2 (Google and Microsoft) login
  • Python package development – abstracted core functionality into a standalone library used across the company, hosted privately in the cloud; we were reponsible for new features, maintenance, and releases

We integrated smoothly with the Fundment frontend team consuming the API (issue triaging, delivering feature requests, bug fixes) and provided onboarding and technical support to other API consumers, e.g. Fundment’s clients.

We also followed software development industry best practices:

  • Automated semantic versioning for the API application (Commitizen), Python package libraries, and Docker images
  • Catching testing, linting, and build errors early on in the development cycle via pre-commit hooks
  • Continuous integration and deployment via GitLab CI/CD pipelines, making use of Docker container and Python package registries
  • Regular standups, planning sessions, backlog refining, code reviews, pair programming
  • Internal technical documentation (manual processes, local development setup, debugging, etc.)
  • Static code analysis (black, isort, mypy)
  • Security scanning of Docker images (Trivy)

In addition, we configured the API to be production ready using an ASGI server (Gunicron + Uvicorn), before deploying the API to various live environments.

Whilst the API was our main focus, we also completed signficant work on migrating Fundment’s techonology to Google Cloud Platform (GCP):

  • Private, dedicated and self-hosted GitLab CI/CD piplelines on GCP Compute Engine instances across multiple repositories
  • Migrated Python packages and Docker containers from GitLab registries to GCP Artifact Registry
  • Migrated various apps across multiple environments (staging, UAT, demo, etc.) to GCP Compute Engine
  • In GCP Compute Engine, deployed apps as containerised workloads via Docker Compose and Managed Instance Groups (MIGs), with each group consisting of Google Container Optimised OS (COS) instances
  • Deployments incurred zero downtime by applying MIG rolling updates
  • Deployments were scaleable, running behind GCP load balancers
  • Deployments were automated via cloud init, Python scripts, and gcloud CLI
  • Deployments made heavy use of YAML configuration files both locally and in Secret Manager so as to be repeatable and easily extendable
  • Setup fluentd logging so application Docker container logs were available in GCP Logs Explorer in an easily readable and queryable format
  • Migrated message broker (rabbitmq) to Compute Engine
  • Proof of concepts demonstrating how various parts of Fundment’s technology stack (queues, recurring jobs, microservices) could be migrated to GCP by using GCP services, e.g. Pub/Sub, Cloud Run, Cloud Scheduler, Cloud Functions