How and why we built a mobile app to solve the parking issue at our new office.

Atrium Parking, a mobile app built with AWS Lambda, DynamoDB and Node.js

Case Study: Creating a Serverless Node.js App with AWS Lambda and DynamoDB Streams

When we moved into our new office in Mohali we gained more (and expertly designed) interior space. But we downsized our exterior space and lost some valuable parking spaces.

Our employees who commute to the office via their cars were now fighting over a select few designated parking spaces. Because each tenant in the building was provided with a limited number of parking slots. 

Our team immediately started brainstorming solutions to this parking space shortage. Thinking about everything from car decals, to designated days, and assigned spots. 

Since we had more cars than allocated parking spots. We needed a more democratic way to assign these available spots. Something that would be fair to everyone.

We ended up landing on a mobile solution that kept track of open parking spots with a series of QR codes. Codes that both drivers and parking lot attendants would use.

The only requirement we put on ourselves was that the solution could only take a few days to create. 

This lead to the creation of a Serverless Lambda DynamoDB App.

Using A Serverless Lambda DynamoDB Framework

Our ‘Parking App’ has two interfaces.

One for the guard or parking attendant. And a separate one for our employees who need to park their car.

These QR Codes are re-created each and every day. With a new and unique design pattern. Prohibitting someone from taking a screenshot and re-using the code from the day before.

One of the main conveniences of our Parking App is that both employees and attendants are notified via push notifications when the parking lot is full.

Giving everyone prior knowledge about the number of free parking spaces available. 

The guard’s interface has a built-in camera scanner to validate the QR code. Once the QR Code is validated, the guard directs the employee to park his/her car in the allotted slot.

The application was deployed using the AWS Serverless framework. Which we used to deploy and set-up an AWS API Gateway and run AWS Lambda functions.

AWS Cognito was set-up independently to provide access control to the mobile application.

Mobile apps built with AWS Lambda

AWS Lambda

Mobile apps built with AWS Cognito

AWS Cognito

Mobile apps built with AWS DynamoDB

AWS DynamoDB

Mobile apps built with Node.js

Node.js

What we learned by building a NodeJS app in 2 days

Our team initially came up with the idea of creating an app by utilizing a geofencing feature. Which would trigger a response when a mobile device enters or leaves a particular area.

Keeping track of the total parking spots already occupied. And more importantly, notifying the other users of free parking spaces.

About Geofencing: Geofencing is typically a built-in feature that uses the Global Positioning System (GPS) and Radio frequency identification (RFID) to define a geographic boundary.

Geofencing is used to keep track of devices and people. Activated when a particular mobile device enters or leaves a defined boundary. After installing a geofencing tool on the target device and enabling the feature, we were able to track their location remotely and precisely.

Making The Most of Geofencing 

Geofencing can be extremely useful when you want to instantly notify potential customers about a sale when they are within close proximity of your physical location. Geofencing is also used by businesses to gather customer data to understand buying capacity. Buying motivation and buying habits altogether.

Geofencing Does Have A Few Drawbacks

First of all, the user has the ability to easily disable the feature on their device. And, Geofencing or location services can also drain more battery when enabled.

This caused an issue for us. Because we have parking spaces located in the basement of the building. Where cellular service is limited. And the geofencing feature would not be effective in detecting the correct location. Due to low connectivity.

Making us scrap the idea of relying on geofencing as the primary means for location data.

So, we needed to create an app that would show the available number of spots as soon as they opened the app. Without having to rely on location-based data.

One of the main advantages of using AWS Lambda is cost.

Here we heavily leverage AWS’ famous pay-as-you-use pricing model. Since we don’t have a need to run these servers the whole day, we do not have to pay for unused capacity. Our Lambdas are only running for brief periods of time, in the mornings and then again in the evenings.

Hence, we only get charged when our Lambdas are running to execute 15 check-ins and 15 checkouts per day.

Additionally, our AWS DynamoDB is serverless.

So, we do not pay for any servers here either.

All in our monthly cost is only $3. 

To learn more about the power of AWS’ Free Tier, check out our recent blog post.

Serverless mobile apps with Node.js
Serverless mobile apps with Node.js
Serverless mobile apps with Node.js

Enter QR Codes

Using QR codes we would be able to track the number of available parking spots. By having the on-duty attendant scan the QR code upon entry and exit.

A Serverless Lambda DynamoDB application was built to be used by both, the guard and the employees.

Every day, the application would generate a new QR code on the employee’s smartphone. The parking attendant would then have an accurate inventory of available and occupied parking spaces. By using location information and the scan history of unique QR codes. 

How does the application detect the number of free parking spots?

We keep a track of the parking spots in a database. An AWS DynamoDB to be specific. We store the maximum number of spots available for each tenant. And are able to query against the inventory whenever a QR code is scanned. 

And since the parking area is shared amongst multiple tenants or companies. We are able to allocate each companies’ number of assigned spots to that individual company profile.

When a user needs to register, we use the email domain of that company. So, in our case when we need to add a user, only someone with an @sourcefuse.com domain can register. And be ready to occupy a parking space from their companies allotment. 

Whenever a QR code is scanned & the tenant checks in, we make an entry in the database against that tenant.

When they check out, again the QR code is scanned and we remove their entry.

The number of entries can’t exceed the maximum parking spots.

Atrium parking a Serverless Lambda DynamoDB App

Built on Native Script

NativeScript is a framework for using web technologies to write cross-platform native apps. 

NativeScript has bindings for VueJS which is what we used in the application. 

Firebase ML Kit for QR Code Reading

ML Kit comes with a set of ready-to-use APIs. Capable of handling many common mobile use cases. Such as:

  • Recognizing text
  • Detecting faces
  • Scanning barcodes
  • Labeling images
  • Recognizing landmarks

The data is simply passed to the ML Kit library. Immediately returning the information needed – all in a few lines of code.

Backed by Amazon Cognito, AWS Lambda, and Amazon API Gateway

Amazon Cognito lets us easily add user sign-ups, sign-ins, and access control.

AWS Lambda lets us run code without provisioning or managing servers. Paying only for the compute time used. 

AWS API Gateway provides us with an endpoint. Wherein the mobile application hits the endpoints, to trigger the Lambda functions.

How AWS Lambda Works

How AWS Lambda works

Other Real-Time Use cases for AWS Lambda

AWS Lambda can be used for data processing. Meaning executing code in response to triggers such as frequent changes in data, shifts in system state, or actions by users is easy. 

Lambda can be directly triggered by AWS services such as S3, DynamoDB, Kinesis, SNS, and CloudWatch. 

Or it can be orchestrated into workflows with AWS Step Functions. Additionally, it can be used for real-time file processing and real-time stream processing. Along with Amazon S3 and Amazon Kinesis respectively.

Real-Time use cases for AWS Cognito

AWS Cognito takes care of the authentication and security our serverless lambda dynamo application needs. It provides all of the following:

  • Secure and Scalable user directory
  • Social and Enterprise identity federation
  • Amazon Cognito User Pools for standards-based identity
  • Multi-factor authentication for your application
  • Access Control for AWS Resources
  • Easy integration with your application

Click here to view all the application’s use cases where SourceFuse made use of AWS Lambda, AWS Cognito and AWS API Gateway.

Atrium parking a Serverless Lambda DynamoDB App

Final Product

The main motive behind creating this Parking App was to allow unbiased parking inside the building on ‘first come, first serve basis’.

The QR code is renewed each day because anybody could capture the QR code from someone else’s’ smartphone and use it the next day. 

Our Serverless Lambda DynamoDB application has been in use for the past five months. And has turned out to be a success for all our employees.

To know more about, how AWS and SourceFuse can help you set up a Serverless Application within a limited span of time, visit here