Automating a task that doesn’t require automation.

Srinibas Misra
4 min readOct 4, 2020

So, here’s a scenario.

I am an avid coder, working in the Cloud domain, who is also a part-time musician and a music producer. So I spend a lot of time coding and developing cloud solutions, along with recording, mixing and producing songs.

Now, once a song has been completed, 99% of the time, I transfer the song to my phone, and I listen to it from there. I listen to it obsessively to figure out if any changes or improvements are required.

Once the changes are done, I export it, transfer it to the phone, listen, repeat.

After doing this thousands of times, I started to get annoyed by the fact that I needed to connect my phone, and copy the file to it. Annoyed might be a strong word. (It’s the laziness speaking.)

So what to do about it? Here’s what I came up with!

If you would like to jump straight to details, the code is available here and here.

Wireless Sync Transfer Service

(Or you can simply call it as an “Universal Air Drop”).

Basically, I put a file in a special folder in my laptop, and within 15 seconds, I get a notification on my phone to download the file. Sweet and simple.

So how would you go about making it?

Let’s get to the details.

Complete architecture.

Components

I am using Google Cloud Platform as the cloud provider for this. Any other cloud provider would also do, if they provide all the required services.

Storage

First things first, we need a place to store the data. And since we are in Google Cloud, what better place to store data than in Google Cloud Storage. I mean, the name has a clue in it.

I am using GCS as the main and the only place where all the files would be stored. Basically anytime, we copy a file to our “special” folder, it automatically gets uploaded to a GCS bucket.

This automatic sync is possible using GCSFuse.

GCSFuse is a small tool that lets you mount GCS buckets onto your local file system. Thus treating a GCS bucket as an external disk.

It doesn’t do so well in terms of performance and transfer speeds, but it does the job for us.

Message Queue

So now that the storage is taken care of, we need a mechanism which would notify us any time a new file is added to the GCS bucket.

Cloud Functions

Thankfully, Google Cloud has a product called, “Cloud Functions”, which are serverless pieces of code, triggered on the occurrences of specific events. The event triggering the cloud function can be a HTTPS request, a message queue push, or an update in a GCS bucket. The last method is very useful for us.

So basically, whenever an object is added to our GCS bucket, the cloud function will be triggered.

But where would the filenames be temporarily stored?

The situation in our case is, our mobile application needs to constantly check if new files are added. It automatically doesn’t get a notification when a file is added.

To do this, we would need some sort of a message queue. The cloud function, when triggered, would push the new file’s details into the message queue.

Pub / Sub

Pub/Sub is a highly scalable and fast message queue provided by GCP.

It has a publisher and a subscriber as its two main components.

The cloud function would be our publisher, and the subscriber would be our API server.

API Server

The API server has two APIs.

  1. Pull API:- This would be used to check if any new messages are present in the Pub/Sub. If any new messages are there, then it would download the files from the GCS bucket and onto the server.
  2. Download API:- This API would be used by the user to download the files from the server.

How would we be using these APIs?

Android App

The Android App would constantly hit the Pull API to check if any new files are added.

If new files have been added, then it’ll generate notifications containing the filename.

On clicking the notification, you will be redirected to the Download API, which would download the file. Thus completing the flow.

Files added to the mounted folder.

I have mounted the GCS bucket onto a folder in my machine, and I’ve added two files to the folder.

Notifications by the Android app to download the files.

Within 15 seconds of it being added to the folder, I get the notifications to download the files to my phone.

Conclusion

All the efforts spent into making this and researching for this, was done just so that I didn’t have to connect my phone to the laptop. Saved probably two minutes (if I’m being generous) of my time.

If curiosity and laziness goes hand in hand for you, indulge in it. Make all the efforts at once so that you don’t have to make tiny efforts later on! That’s the motto I live by!

Happy coding!

All the code is available on my GitHub.

Android App:- https://github.com/srinibasmisra97/Air-Drop-Android-App

Cloud Function and API Server:- https://github.com/srinibasmisra97/Air-Drop

And if you’d like to check out my music as well, feel free to see my Instagram and YouTube channels.

--

--