A Conspiracy

Then Saul said unto his servants that stood about him, Hear now, ye Benjamites; will the son of Jesse give every one of you fields and vineyards, and make you all captains of thousands, and captains…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Using trees for real

A lot of software engineers go through a lifetime without using the data structure: trees. Trees can be a very powerful way to operate your data, and can drastically reduce computations (linear → logarithmic) needed for a problem. Our use case was not to minimize computations but just to organize data in a refined manner. I want to share a mundane software/full-stack project where I applied this.

We wanted to integrate Freshdesk (a customer service software providing helpdesk support) into our platform so that our users could connect with our customer-support agents. We have custom UIs built, which interact with Freshdesk APIs to perform operations.

The backend service is called Blender, and the architecture is straightforward. Our frontend calls Blender via HTTP, Blender then calls Freshdesk APIs, there’s also a local database where we cache data. We are only storing ticket fields and not conversation/chats. This helps us serve all basic ticket information to a user without hitting the get tickets API from Freshdesk (we use Freshdesk webhooks to keep this data in sync).

One specific API which was very limiting to us was the Freshdesk attachment API: they have a limit of 15MB per attachment. We want our customers to send us much larger attachments, such as a video of their gameplay/issue. The idea is to use AWS S3. Uploading and storing files on S3 is straightforward, but how do we integrate it? What are our challenges:

Initially, I just stored a JSON full of data on the note. Then, when the Freshdesk Conversation API was returned, I would try to parse a JSON on every private note and figure out information.

My manager requested that we have a bold header, relaying to the agents this note shouldn’t be deleted, and the data should be a little more readable. Agents would have to click on the link and read the message sent with the attachment.

This is what the final output looks like:

I decided to write my own data interchange format like JSON/XML/HTML.

Here’s an example of what that looks like:

Having a fully custom tokenizer + parser for a data interchange format allowed me to be very structured with my information. I decided that the (meta) tag would have JSON, and the (message) part would have YAML, which makes it readable. There are also tags with (^ and ^) which denote the start and end of the data. These tags contain long hashes known to Blender, which adds an extra layer of security to the user’s data.

To operate on this data we need to construct a tree. Here are the types and function specifications which need to be written to make this work:

blenderParser uses a stack to construct a tree, returning the root node of the tree.

The tree implementation took me about 2hrs to code up and write test cases for. It gives us a strong framework to build features on.

Add a comment

Related posts:

If You Feel Overwhelmed

A lot of us can relate to the feeling of being overwhelmed. One thing goes wrong and it spirals from there; each new problem adding a heavier weight to the rest. Oftentimes, in this state, it is hard…

GET THROUGH THE LIST OF FEATURES OFFERED BY SUMMERHILL HOMES FOR SALE

When it comes to choosing a home or a house, you ought to look for the best possible one for you. Investing in a house is for a lifetime, as this is the place where you look for a comfy space after a…

TCR Therapy

T-cells are a subset of lymphocytes that play a large role in the immune response. The T-cell receptor (TCR) is a membrane-bound protein complex found on the surface of T cells. TCR will recognize…