We have all seen some footage of a car with a dummy doll on board that was crashed intentionally. Unfortunate for that car, but these crashes provide life-saving information on how the car behaves in a specific type of accident.
Euro NCAP is a vehicle safety rating system that tries to find out how safe (or unsafe) a car is by doing those crash tests. Each car gets a rating from zero to five stars. In addition, Euro NCAP collects all available information about a car that may be important in the event of a rescue operation. They create rescue sheets which, among other things, contain the position of the airbags, the position of the fuel tank and information about how someone can be safely rescued from the car.
Euro NCAP went looking for a way to make this information accessible to rescue workers during an intervention. To achieve this, In The Pocket developed a mobile application for both iOS and Android devices, accompanied by a cloud application to serve the necessary information.
To serve the mobile application with data, In The Pocket developed an efficient API to fetch the data. The setup is fairly simple: Euro NCAP uses Microsoft SharePoint to manage its data and documents. Those documents and data are synchronized daily between SharePoint and the database connected to the API. Taking into account the requirements, budget and timing, we decided to use a combination of managed Google Cloud services to develop the platform. This way our application runs on an architecture that takes full advantage of modern cloud-native technologies.
Data is stored in Cloud Firestore, the latest fully managed NoSQL database from Firebase and Google Cloud Platform. Data can be retrieved directly from the database via the native SDK. That way, an extra API layer is not necessary. For a project like this, with a simple data model, the use of Cloud Firestore results in a substantial saving of cost and development time.
Cloud Storage buckets
The pictures of cars and rescue sheets are saved in Google Cloud Storage bucket. Buckets are ideal to serve static files. Documents can be uploaded and downloaded with a simple API provided by the native SDK.
The business logic is split up into multiple Cloud Functions. With Cloud Functions, you don’t have to provision servers, they make up what the industry calls an event-driven serverless compute platform. You also only have to pay for the time your code runs. For a synchronization task that runs once a day, this is the perfect solution. In addition, scalability is handled automatically. We developed the Cloud Functions in TypeScript that use a Node.js runtime.
Cloud Pub/Sub is a messaging service that allows asynchronous communication between autonomous services or applications, using a publish-subscriber pattern as you might have guessed. It is used to transfer data between the Cloud Functions. A Cloud Function is triggered when there’s a new event on the topic that it is listening on.
Cloud Scheduler, Google Cloud’s managed cron job scheduler, is used to start the synchronization. It fires an event on Pub/Sub that gets picked up by a Cloud Function. From then on, the synchronization process has been initiated.
The project has two Cloud Functions. One Cloud Function is responsible for the synchronization of all data, the other downloads the documents and pictures and stores them in a Cloud bucket.
Cloud Scheduler triggers the data synchronization daily by firing an event on Pub/Sub. The event gets picked up by the Cloud Function and starts fetching the data from SharePoint to store in the Cloud Firestore database. While handling the data, the first Cloud Function fires events with information about rescue sheets or car pictures that have to be downloaded. These events trigger the execution of the second Cloud Function, which downloads and stores the file in a Cloud bucket.
By design, the Cloud Functions scale automatically, so based on the number of events fired, there can be multiple instances of the same Cloud Function running. This makes sure the files are handled very fast.
Infrastructure as Code
We use Terraform, the industry-leading tool to manage cloud infrastructure, for the provisioning of our cloud infrastructure and the deployment of our Cloud Functions. All cloud resources are defined and configured in source controlled terraform files, the so-called Infrastructure as Code.
The use of Terraform allows us to spin up different environments very easily without having to do manual actions in the Google Cloud Console. In combination with our CI/CD pipeline, the setup of the infrastructure and deployment of the code for this project is completely automated.
For the Euro NCAP project, the combination of managed Google Cloud Services and Terraform appeared to be the perfect choice. With minimal effort and development time, all data was made available for the mobile application. Together with Euro NCAP, In The Pocket made our world a safer place.