January 27, 2021

How Prisma Helps Rapha Manage Their Mobile Application Data

Rapha is a company dedicated to redefining comfort, performance, and style for cyclists around the world, whether beginners or World Tour professionals. Learn how Prisma helps Rapha build consistent data APIs across various teams and platforms.

How Prisma Helps Rapha Manage Their Mobile Application Data

Summary

Prisma helps Rapha deliver a consistent user experience across web, mobile, and physical store locations by making it easy to access user data:

  • Prisma simplifies access to their PostgreSQL data for both their Android and iOS applications
  • Prisma Migrate manages and applies schema changes in their development and production environments
  • Prisma helps Rapha stay flexible, allowing them to evaluate data storage options while maintaining a consistent developer experience

Rapha is a company dedicated to redefining comfort, performance, and style for cyclists around the world, whether beginners or World Tour professionals. Cyclists love their products and their commitment to the community and the sport.

In addition to being an activewear brand, Rapha is a resource within the cycling community. They regularly organize and sponsor unique rides and events and founded the Rapha Cycling Club in 2015 to bring cyclists together. The Rapha Foundation, meanwhile, is dedicated to funding non-profit organizations to help build a better future for the sport by supporting the next generation of racers.

Rapha's Platforms and Data Infrastructure

Rapha's involvement with its community provides many unique opportunities and challenges. Offering products and services both online and in Rapha Clubhouses throughout the world helps them connect with users where ever they happen to be. These user touchpoints include Android and iOS applications, an e-commerce website, and a variety of web content like blog posts.

A side effect of interfacing with users in so many unique mediums is that a variety of systems are involved in managing user data. Their data infrastructure reflects this.

Rapha's data architecture

Rapha's web team addresses its data requirements primarily with:

  • SAP Hybris and Commerce Cloud: manages their e-commerce website data including user information related to purchases

Meanwhile, Rapha's mobile team uses a stack that includes:

  • PostgreSQL: their main database hosted on Amazon RDS
  • Prisma 2: next-generation ORM for Node.js and TypeScript
  • Nexus Schema: TypeScript and JavaScript type definitions to generate GraphQL APIs
  • Apollo Server: a GraphQL server to serve the generated API
  • Contentful: an API-driven content management solution the team uses to handle blog posts and other content

Rapha uses Prisma to develop and manage the data API that their mobile applications rely on.

The majority of the team's data is stored in a PostgreSQL database running on Amazon RDS. Rather than interfacing with the database directly, they use Prisma to build and manage schemas that serve as the basis of their data API. They can then use Apollo server to serve the API to their mobile applications.

The services above are all packaged into Docker containers and deployed to Amazon's Elastic Container Service. Long-running and asynchronous tasks are added to Amazon's SQS message queuing service and consumed by Amazon Lambda functions. Rapha relies on Cloudflare at the edge to accelerate access for users around the world.

What Rapha Needed From Its Data Layer

Rapha wanted tooling to help their mobile team develop against their database quickly and safely. As a small team supporting both iOS and Android applications, they wanted to make it easy to develop and deploy schema changes in an organized manner. This meant synchronizing changes between the backing database and the GraphQL API that their mobile applications interface with.

In addition to this, they wanted more control and flexibility to make changes down the road as their requirements evolve. Whether moving to new technologies by choice or necessity, Rapha wanted to be able to maintain a stable interface to their data regardless of what was responsible for managing and serving it.

Rapha evaluated Prisma as a way to build a data API to address both of these concerns.

How Prisma Helps Abstract Rapha's Data Infrastructure

Rapha's mobile team uses Prisma to help them develop its GraphQL API for their PostgreSQL data. This API is then served by Apollo server and consumed by both their iOS and Android applications.

With Prisma, the team can modify their data structures by making changes to the Prisma schema file. The schema file serves as a single source of truth for the structure of their data models. It is used to update the tables in the underlying database and allows the team to easily build changes into the API.

By combining Prisma with their GraphQL API, Rapha is able to abstract the data source and make it easily accessible to each platform. Prisma is responsible for managing changes between the API layer and the database. Meanwhile, the GraphQL API created from the Prisma schema provides a unified interface for their applications. Prisma's type-safety helps make updates to the API easier and safer to implement. Together, they allow the team to evolve their data models to respond to changing requirements.

Managing Migrations

As Rapha's mobile applications evolve, changes to the database schema must be managed carefully to ensure that the API and application versions remain compatible. Prisma provides tooling to safely deploy changes to their development and production environments.

Since Prisma defines its data structures for applications and databases in a schema file, changes to the data model are centralized. Prisma Migrate can be used to detect changes to the schema file and generate SQL migration files.

These can be stored in version control and run against databases to transform their data structures. When it is time to deploy the schema change, the team can use Prisma Migrate to apply the changes to the database automatically as part of their CI/CD pipeline or they can run the generated SQL script against the database manually.

Building for the Future

Prisma's abstraction over Rapha's PostgreSQL database helps them prepare for a time when they might have additional data sources. While their Prisma configuration currently only manages the schema of a single database, it acts as a framework for additional changes.

Over the next few years, Rapha foresees their data API growing as they offer new services and integrate experiences across their platforms. Prisma will allow them to choose the databases that fit the needs of each service while minimizing the impact on their developer experience. This is relevant when choosing the databases for their new services and when reevaluating whether the databases they currently rely on are still the best choice.

Conclusion

Rapha's mobile and web platforms continue to grow with new services, products, and events always on the horizon. The development team is able to provide users of their e-commerce platform, mobile apps, and physical Rapha Clubhouses a unified, personal experience.

Don’t miss the next post!

Sign up for the Prisma Newsletter