Hyperledger Sawtooth – Introductory tutorial

In this blog post, I will try to quickly cover Hyperledger Sawtooth basics and explain how to get to a productive development setup starting from the Sawtooth core codebase.

Hyperledger is an open-source collaborative effort to create industry standard blockchain technologies. It is backed by the Linux Foundation. You can read more about the effort here – https://www.hyperledger.org/about.

This edX course would be a good starting place for anyone interested in Hyperledger – https://www.edx.org/course/blockchain-business-introduction-linuxfoundationx-lfs171x.

Sawtooth is one of the mature projects (1.0 released in Jan 2018) within Hyperledger, initially contributed by Intel. It is designed with Enterprise use-cases in mind. Among other things, Sawtooth introduces a novel consensus algorithm called Proof of Elapsed Time (PoET), has support for permissioned private blockchains, parallel transaction execution, dynamic switching of consensus algorithms, compatibility with Ethereum (via Seth transaction family) etc. It also has development support for a broad language base including Python, Go, Java etc.

Why this post?

Sawtooth is one of the most well documented piece of open-source software that I’ve come across.  I would recommend anyone interested in learning Sawtooth to go through it – link.

Having said that, I feel that the level of information in the docs can be a bit daunting, especially for someone new to blockchain. Also, in my case, the fact that I wasn’t very comfortable with docker added an additional layer of indirection/complexity in the learning process. I need to be able to see how something starts up beginning from the code to fully understand how it works.

I couldn’t find any tutorials on Sawtooth outside the documentation as of today. I reached out to the friendly experts hanging out in the  Sawtooth Rocket chat channel to clear many issues I came across while trying to play with Sawtooth. This post is my effort to give back to the community, in the form of a basic intro to setting up sawtooth from scratch.

Components

Sawtooth_node
Sawtooth components

Transaction Processor

The transaction processor maintains all domain specific business logic for a transaction family (similar to smart contracts) such as:

  1. Serializing/Deserializing the state stored in the ledger to domain objects.
  2. Providing the business logic for validating transactions

Validator

The validator handles consensus, all blockchain read/writes, peer interaction etc. It is agnostic of the business logic. In fact, one validator process running in a host can be connected to multiple transaction processor processes.

Client

Clients (CLI, web services etc.) interact with a transaction processor via a REST API (a separate process).

If you are interested in playing around with Sawtooth using pre-built images, the installation section of Sawtooth would be helpful – link. You can use docker images, Ubuntu packages or install Sawtooth from the AWS marketplace.

Getting your hands dirty

In this section, I will try to get a working instance of Intkey transaction processor (TP) running locally in Python. Intkey is a sample TP for setting, incrementing and decrementing values in a dictionary. First of all, checkout the sawtooth-core code-base

git clone https://github.com/hyperledger/sawtooth-core

We will still use a provided docker container for running all our processes to save us the trouble of getting the right version of all the dependencies required. In our case, we will use the sawtooth-dev-python image. Also, we will build and use the validator and REST API directly (not from code) as these don’t need to be changed by application developers.

Setup the validator

Build everything (install docker if you haven’t):

$ cd sawtooth-core/docker
$ docker build . -f sawtooth-dev-python -t sawtooth-dev-python

Now if you list your docker images, you should see the newly created one:

$ docker images
REPOSITORY          TAG    IMAGE ID     CREATED    SIZE
sawtooth-dev-python latest ecf3ae086754 2 days ago 817MB

Next, let’s start a container and get inside it:

$ cd sawtooth-core
$ docker run -v $(pwd):/project/sawtooth-core -it sawtooth-dev-python bash

This should start a container using the sawtooth-dev-python image and get you to a root prompt prompt within the container with our present working directory (sawtooth-core) mounted as /project/sawtooth-core.

root@43edef3881be:/project/sawtooth-core# ls

Before we start up the validator, we need to do some setup here. Basically create the genesis block and required keys.

# sawtooth keygen
# sawset genesis
# sawadm genesis config-genesis.batch

Next, let’s start up the validator:

# sawadm keygen
# cd bin/
# sawtooth-validator -vv

You would want to keep the validator running for the rest of the steps to work. For that, you will need to connect to the container from a different terminal. For that, you need to find the container id for the container that you just created:

$ docker container ls
CONTAINER ID IMAGE               COMMAND CREATED   STATUS    PORTS              NAMES
43edef3881be sawtooth-dev-python "bash" 8 days ago Up 8 days 4004/tcp, 8008/tcp keen_keller

Now, to get into the container from this new terminal, you just need to do the following:

$ docker exec -it 43edef3881be bash

Now, we need to start up the settings transaction processor which is required for the validator to function correctly:

# cd bin/
# settings-tp -vv

You should see some logging in the validator terminal tab/window along these lines now:

[2018-04-12 07:25:27.657 INFO processor_handlers] registered transaction processor: connection_id=f519f4ff0bd1e26968d5bcd76cd71eed88d097c5a4846798c35f5d9c5efeb8845ea65fdf2172c12c7b4a226fc4214c18f6989c4048e0012c2fb5378252d67a08, family=sawtooth_settings, version=1.0, namespaces=['000000'], max_occupancy=10
[2018-04-12 07:25:27.705 INFO genesis] Genesis block created: 69f85216c3137fdc0ee31f8d754dfd134198b6d97f31c45e52ccbb3af356bbbe443aa38ba6a3380a7aab734b939881dbb198367311423b0b8d9aa39569d186eb (block_num:0, state:2cd74660fc59b472699aad3f6da884ae636191673e6773e6d81b9c8987065e9f, previous_block_id:0000000000000000)
[2018-04-12 07:25:27.709 INFO interconnect] Listening on tcp://127.0.0.1:8800
[2018-04-12 07:25:27.712 INFO chain] Chain controller initialized with chain head: 69f85216c3137fdc0ee31f8d754dfd134198b6d97f31c45e52ccbb3af356bbbe443aa38ba6a3380a7aab734b939881dbb198367311423b0b8d9aa39569d186eb (block_num:0, state:2cd74660fc59b472699aad3f6da884ae636191673e6773e6d81b9c8987065e9f, previous_block_id:0000000000000000)

There is one more piece required before we can get to our Intkey transaction processor – the REST API. Again, from a new terminal, get into the container and run:

# cd bin/
# sawtooth-rest-api -vv

At this point, you have a functional sawtooth validator. You can play around with it using the sawtooth command. Some examples:

# sawtooth state list 
ADDRESS SIZE DATA
000000a87cb5eafdcca6a8cde0fb0dec1400c5ab274474a6aa82c12840f169a04216b7 110 b'\n...
HEAD BLOCK: "69f85216c3137fdc0ee31f8d754dfd134198b6d97f31c45e52ccbb3af356bbbe443aa38ba6a3380a7aab734b939881dbb198367311423b0b8d9aa39569d186eb"
# sawtooth transaction list
TRANSACTION_ID FAMILY VERS SIZE PAYLOAD
5964642adb957ca994f5789e9a5f9930853c20359a8adbc5c18ecf4b338fc9a00f544f42cf17d7cdc79531727fbdb307f4143c8104ec9ed0e5c3557a476cccdb sawtooth_settings 1.0 131 b'\x08\...

You can also directly query the REST API as follows:

# curl http://localhost:8008/blocks
{
 "data": [
 {
 "batches": [
 {
 "header": {
 "signer_public_key": "0317f01f8958bc6d404d1ffe88770fe927fef63022216f24484906760873501d7f",
 "transaction_ids": [
 "5964642adb957ca994f5789e9a5f9930853c20359a8adbc5c18ecf4b338fc9a00f544f42cf17d7cdc79531727fbdb307f4143c8104ec9ed0e5c3557a476cccdb"
 ]
 }.. // trimmed to keep it short

Intkey

The Transaction Processor

You’ll notice that pre-build Intkey transaction processor binaries are also available in the bin folder. However let’s try to run it from directly from the code. The main.py (code link) in the following directory actually starts the example Intkey processor:

/project/sawtooth-core/sdk/examples/intkey_python/sawtooth_intkey/processor/main.py

We need python3 for some of the dependencies. But if you directly try to run main.py from python, you will run into couple of issues. You’ll notice it depends on the sawtooth_sdk module, which in turn depends on sawtooth_signing module. Lets build them first.

// First, lets install sawtooth_signing
# cd /project/sawtooth-core/signing/
# python3 setup.py install

// Next, lets install sawtooth_sdk
# cd /project/sawtooth-core/sdk/python/sawtooth_sdk
# python3 setup.py install

Now, we need to tweak the main.py file a bit to work in run-from-source approach.

It tries to import from sawtooth_intkey.processor.handler module, which it will fail to find. The handler.py is however right besides the main.py in the same directory. So lets modify main.py to use that:

- from sawtooth_intkey.processor.handler import IntkeyTransactionHandler
+ from handler import IntkeyTransactionHandler

At this point, we should be able to run main.py without any errors. But it will exit without doing anything. Thats because no-one is calling the main method. Let’s add a bit of code at the end of the file to do that:

if __name__ == "__main__":
    main()

Notice that you can modify the file in your host machine itself i.e outside the container. Since the sawtooth-core folder is shared with the container, it will be automatically up-to date with the latest code.

Now, your Intkey transaction processor is ready to roll! You can try some of the commands as follows:

# python3 main.py -V
sawtooth-intkey (Hyperledger Sawtooth) version UNKNOWN

Here is how you really start it:

# python3 main.py -vv
[2018-04-12 08:09:31.254 INFO core] register attempt: OK

You should see the validator also logging in its terminal the fact that intkey TP connected successfully. Something like:

[2018-04-12 08:09:31.248 INFO processor_handlers] registered transaction processor: connection_id=acf1ed62db9a2e18c88af958532ac7c9857d6db50d951348eabda8ba5e0913e9a4deeb3fa607cbf6897efdc0585559ea38470cfbbe96141668369db16d3f45a5, family=intkey, version=1.0, namespaces=['1cf126'], max_occupancy=10

Intkey CLI

Let’s try running the CLI to interact with the Intkey transaction processor.

You will notice the provided intkey_cli.py file references other files in its directory using sawtooth_intkey.client_cli.xyz path. For it to be able to find these files correctly, lets copy it to the appropriate location:

# cd /project/sawtooth-core/sdk/examples/intkey_python/
# cp sawtooth_intkey/client_cli/intkey_cli.py .

Next, similar to the earlier main.py, we need to add an entry point for the intkey_cli.py. Add the following snippet at the end of the file:

if __name__ == '__main__':
    main_wrapper()

This completes our setup! Let’s play around with it:

# python3 intkey_cli.py --help
usage: intkey_cli.py [-h] [-v] [-V]
 {set,inc,dec,show,list,generate,load,populate,create_batch,workload}
 ...

optional arguments:
 -h, --help show this help message and exit
 -v, --verbose enable more verbose output
 -V, --version display version information

subcommands:
 {set,inc,dec,show,list,generate,load,populate,create_batch,workload}
 set Sets an intkey value
 inc Increments an intkey value
 dec Decrements an intkey value
 show Displays the specified intkey value
 list Displays all intkey values

If you list all the entries in the blockchain now, it should be empty (as we did not insert any):

# python3 intkey_cli.py list

Now, sets try setting and getting a key-value pair:

// Set key 'a' to value 10
# python3 intkey_cli.py set a 10
{
 "link": "http://127.0.0.1:8008/batch_statuses?id=46f82450d39c6c59968efc83a15669477804ccb9ad569a7b61bebecf6cf55f931e0bd19c4de42926b7ce90b320b3ffe50e411130957b1812f8e4f2a45865c8ed"
}

//Let's try listing again
# python3 intkey_cli.py list
a: 10

// Let's try reading the key
# python3 intkey_cli.py show a
a: 10

// Let's try incrementing 'a' by 2
# python3 intkey_cli.py inc a 2
{
 "link": "http://127.0.0.1:8008/batch_statuses?id=8d2f5e0ef324ba15a5cd95392cd65caf6df7124f7c06dc0531feb77cfda49f047c765cb96557a3de0f91902e7b2b3212111b997fe663c7b9bb610bd7a7ad6759"
}

// Show again
# python3 intkey_cli.py show a
a: 12

You can also do batch import of random keys (for testing, measuring throughput etc.) as follows:

// Create 1 batch file with operations on 5 keys
# python3 intkey_cli.py create_batch -K 5 -c 1
Writing to batches.intkey...

// Load the batch file
# python3 intkey_cli.py load
batches: 2 batch/sec: 72.39234705765597

// List the added keys
# python3 intkey_cli.py list
a: 12
ZmyetF: 30086
ReocMV: 59247
CINQSf: 57819
BWADZo: 39267
RoDdEV: 47475

You should be able to see the corresponding logging for each of these commands in the REST API, transaction processor and validator terminal consoles.

In summary, we started by checking out the sawtooth-core codebase and ended with a docker container running the following:

  1. Validator
  2. Settings Transaction Processor
  3. REST API
  4. Intkey Transaction Processor (from source)
  5. Intkey CLI (from source)

This concludes my hands-on overview of working with Hyperledger Sawtooth.

I hope this will be helpful as a good starting place for developers trying to create their own custom transaction families in Sawtooth. In case you run into any issues while following these instructions or have any questions, please let me know. I’ll try to help you out. As I mentioned earlier, the Sawtooth Rocket chat is a good place to get help from experts in case you are stuck.

Advertisements

Spacemacs – Among the stars aboard the Evil flagship (vim)

Screen Shot 2018-04-09 at 6.23.06 PM

I’ve been using Spacemacs as by IDE/editor of choice for about half a year now. I absolutely love it! It’s basic premise is that

“The best editor is neither Emacs nor Vim, it’s Emacs and Vim!”.

In this post, I will try to explain briefly what it is and how I use it in a way that is newbie friendly.

Background

I’ve been programming for over 10 years now, professionally for about 4 years. I’ve worked in a variety of different languages over time – HTML/CSS/JS, C/C++, PHP, Python, Java and most recently Clojure.

Till now, I did not have a consistent IDE/Editor. For web development, I used to use Sublime and later Atom. For Python, PyCharm. For Java, I used to use Eclipse and switched to IntelliJ later (I still use IntelliJ + IdeaVIM for Java as I will explain later). I used to use basic Emacs in college for C/C++ projects and basic Vim at work whenever I needed to quickly make small changes to files when sshed into servers.

The original reason I made the switch to Spacemacs was because I couldn’t find a good idea for Clojure elsewhere. CounterClockwise, the Eclipse Clojure plugin is not being maintained actively. Cursive, the IntelliJ plugin is paid. The most recommended/actively developed/open-source IDE for Clojure Cider (Clojure(Script) Interactive Development Environment that Rocks) was available only for Emacs and its derivatives such as Spacemacs.

cider_repl
Clojure development using CIDER, complete with a fully featured REPL having auto-complete and doc-string tooltips.

However, now Spacemacs in Evil (Vim) mode has become my IDE/editor of choice for most languages and for any editing outside programming as well. Spacemacs makes it a lot easier to get to a really productive state without having to do a lot of research online, tuning your dotfiles, installing plugins etc – it comes with batteries included!

The Vim Modal editing

Spacemacs supports 3 modes of usage:

  1. Among the stars aboard the Evil flagship (vim)
  2. On the planet Emacs in the Holy control tower (emacs)
  3. A hybrid mode combining 1 and 2

If you are new to both Emacs and Vim, I strongly recommend using Spacemacs in Evil (Vim) mode. Emacs/Hybrid mode needs to be considered only if you are already comfortable with the Emacs keybindings.

Vim or its modal editing lets you edit text at the Speed of Thought. Many people argue that coding is more about thinking and less about churning out code, and that the minimal time savings you get from optimizations such as Vim is negligible. I disagree:

  1. Vim helps you make editing as least intrusive to your thinking as possible
  2. The small savings add up across your profession as a coder.
  3. As a programmer, having a hackable/fully-programmable editor gives you the flexibility to program your editor as per your needs.

Sylvain Benner, the creator of Spacemacs has written an excellent short piece on ‘Modal editing – why and how‘ that I highly recommend. In fact, I recommend going through that whole article (Beginner tutorial) if you are new to Spacemacs.

Vim itself has a steep initial learning curve. But it pays off greatly after the first few weeks if you write code as a profession. Some helpful/interesting Vim resources to get you started:

  1. Why Vim? – http://www.viemu.com/a-why-vi-vim.html
  2. Vim interactive tutorial – http://www.openvim.com/
  3. Vim adventures (interactive game) – https://vim-adventures.com/
  4. Vim Creep (story) – https://www.norfolkwinters.com/vim-creep/
  5. Vim cheatsheet – http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html

There are lot of good video tutorials on Vim in Youtube too if that’s what you prefer. Here is one I liked – Learning Vim in a week (link).

In short, Vim lets you edit text similar to how you think about editing text. Examples:

  1. Typing ciw lets you change the current word (change in word)
  2. Typing di” lets you delete everything within two double-quotes (delete in “)
  3. Typing dt> lets you delete everything till > (delete till >)

You get the idea. These are executed in the normal mode, where you will spend most time. There is much to be said about the composability of vim commands too (some other time).

Pro tip: It is very highly recommended that you remap your Control (Ctrl) key to the Capslock key once you start using Vim. You won’t need to move your fingers from home row much with this change. For Mac, I used Karabiner to remap the keys.

Why Spacemacs?

Emacs,  “a great operating system, lacking only a decent editor” – http://en.wikipedia.org/wiki/Editor_war

At the same time, Vim is said to suffer from a less than ideal scripting language and window management capabilities. Spacemacs gives you the best of both worlds.

Two primary reasons which I went with Spacemacs were:

  1. Batteries included
  2. Mnemonics

Batteries included

This was the biggest factor for me. I’ve tried to transition into using Vim in the past. To get to a really productive dev environment, you need to spend significant time going through various forums, identifying the plugins you need, installing them using some package manager like Vundle etc. This can be quite daunting for a newcomer.

Spacemacs has this concept of layers. For example, each language has its own layer. When you install a layer, Spacemacs installs the best community-curated plugins for that language for you. Even better, it auto-detects which layer to install when you open a new type of file and asks you whether you want to install it. A simple ‘y’ and you’re set to go!

The layers that I have installed as of April 2018:

dotspacemacs-configuration-layers
 '(ruby
 php
 csv
 yaml
 clojure
 javascript
 python
 java
 c-c++
 markdown
 html
 ivy
 (auto-completion :variables
                   auto-completion-enable-help-tooltip t
                   auto-completion-enable-snippets-in-popup t)
 better-defaults
 emacs-lisp
 git
 markdown
 org
 (shell :variables
        shell-default-height 30
        shell-default-position 'bottom)
 ;; spell-checking
 syntax-checking
 version-control)

Mnemonics

Another issue in that I had faced in the past was learning and memorizing all the keyboard shortcuts. Vim/Emacs has evolved over more than 20 years now. Different plugins were created at different points of time. Hence there is no consistency or logical grouping for these.

Spacemacs solves that by taking all the plugins/shortcuts and logically grouping them by mnemonics. Spacebar is the leader key (main key for issuing any command). That itself is an improvement over other editors which strains your little fingers and can result in carpal tunnel syndrome (CTS).

To give some example of how mnemonics work:

  1. SPC w gives you all the window related commands.
    1. SPC w d deletes a window
    2. SPC w m maximizes a window
  2. SPC b gives you all buffer related commands.
  3. SPC g gives you all git related commands.

Spacemacs comes with the which-key plugin which shows a helpful menu whenever you press SPC so that you don’t need to memorize all the shortcuts.

spacemacs_which_keys
Spacemacs which-keys plugin helps find what you are looking for

If you are interested in learning more about Spacemacs, I highly recommend the Spacemacs ABC tutorial series by Eivind Fonn – Youtube playlist link. It is a series of 8 videos, in each of which Eivind explores one ore more keys under SPC in detail.

Some cool stuff

These are some of the cool features that made the whole experience more fun.

Magit

Magit is a plugin for git version control. Till now, I generally used to prefer command line git for all version control use-cases. But the 3 window Ediff merging capability of Magit is something that sold me completely. Resolving merge conflicts were never so much fun!

magit
3 window Ediff merging using Magit. Courtesy: Magit Ediff tutorial

Undo Tree

Shortcut: SPC a u

spacemacs_undo_tree
Undo tree lets you browse through all past changes

With most modern editors, we are used to a linear timeline of changes. If you go back to your past change and modify something, you effectively lose history of all the things you did after that change. With the undo tree, your entire history is preserved and you can easily navigate to any point in time including any branching in history you did.

Vim Macros

You can record and replay commands using Macros. A good introduction here – link. This can be pretty powerful if you need to do something repetitive in a smart way.

Shortcut to record: q<letter><commands>q
Shortcut to replay: <number>@<letter>

You might think these are pretty esoteric tools and of not much practical use. I too though so until I came across multiple situations where I was able to use them effectively.

Vimium (Bonus)

Once you get to using Vim, you will resent having to take your hands off the home row (where hjkl keys are situated) at any time. Moving your hands to the trackpad could feel like too much work.

Worry not, Vimium comes to the rescue – https://vimium.github.io/.
Its a plugin for Chrome (you have Vimari for Safari, not as feature-rich as Vimium) that lets you navigate the web using your keyboard, mostly with keys in the home-row.

vimium.png
Vimium lets you navigate the web using your keyboard

Being Pragmatic

Even though I’ve talked so much about Spacemacs, I have realized that it might just not be the right tool for some cases. In particular, for me, it was not working for Java development.

I tried all the options available in Spacemacs. Eclim, which comes with the Java layer, essentially runs a headless eclipse process in the backend. However, it is pretty slow. Other options like malabar, jdee or meghanada were either outdated, not being actively developed or not working. It’s difficult to write Java without proper auto-complete or go-to-definition etc. features.

I found that IntelliJ team offers an IdeaVim plugin that lets you use IntelliJ with Vim keybindings. This along with the distraction free mode (Cmd + I) gave me a near similar experience to Spacemacs, but with all the Java goodness.


I am still learning a lot in both Vim and Spacemacs. I hope to update this post with more interesting/useful features that I uncover over time.

Artificial Intelligence – Experience

I recently completed the Artificial Intelligence course (CS 6601) as part of OMSCS Fall 2017. The course gives an good overview of the different key areas within AI. Having taken Knowledge Based AI (CS 7637), AI for Robotics (CS 8803-001), Machine Learning (CS 7641) and Reinforcement Learning (CS 8803-003) before, I must say that the AI course syllabus had significant overlap in many areas with these courses (which is expected). However, I felt the course was still worthwhile since Prof. Thad taught these topics in his own perspective, which made me look at these topics in a different light. Prof. Thad also tried his best to make the course content interesting and humorous, which I really appreciated.

Course Outline

  1. Game Playing – Iterative Deepening, MinMax trees, Alpha Beta Pruning etc.
  2. Search – Uniform Cost Search, Bidirectional UCS, A*, Bidirectional A* etc.
  3. Simulated Annealing – Hill Climbing, Random restarts, Simulated Annealing, Genetic Algorithms etc.
  4. Constraint Satisfaction – Node, Arc and Path consistency, Backtracking, forward checking etc.
  5. Probability – Bayes Rule, Bayes Nets basics, Dependence etc.
  6. Bayes Nets – Conditional Independence, Cofounding cause, Explaining Away, D Separation, Gibbs Sampling, Monty Hall Problem etc.
  7. Machine Learning – kNN, Expectation Maximization, Decision Trees, Random forests, Boosting, Neural nets etc.
  8. Pattern Recognition through Time – Dynamic Time Warping, Sakoe Chiba bounds, Hidden Markov Models, Viterbi Trellis etc.
  9. Logic and Planning – Propositional Logic, Classic planning, Situation Calculus etc.
  10. Planning under Uncertainty – Markov Decision Processes (MDPs), Value iteration, Policy iteration, POMDPs etc.

The course used the classic textbook in AI –  Artificial Intelligence – A Modern Approach (3rd Edition) by Peter Norvig and Stuart Russell. Some chapters (such as Logic and Planning) was taught by Peter Norvig himself whereas few others were taught by Sebastian Thrun. There is no arguing that the course was taught by the industry best.

Screen Shot 2018-01-07 at 6.30.34 PM
The iconic cover of Artificial Intelligence: A Modern Approach

There were 6 assignments (almost one every alternate week) which required proper understanding of the course material and decent amount of coding (in Python). There was an open book midterm and final exam as well. Even though these were open book, these involved significant amount of work (researching and rereading the text, on paper calculations etc.). Overall, completing these forces one to really understand the concepts, which I really liked.

Summary Stats

  1. Average time spend per week – approx. 20 hours (including whole weekends on assignment due weeks)
  2. Difficulty (out of 5) – 4.25 (which is what I would rate ML too, and these two would top my list)
  3. Rating – 4/5

Startup Diaries – FindAuto

This is the second post in my Startup Diaries series.

1797511_264876753686531_1741240032_n

I started FindAuto along with some of my college classmates back in 2013. The idea was to connect customers to nearby auto-rickshaws easily using modern technologies. This was before Ola or Uber (or any smart cabs) were available in Kerala.

Inception

The idea for the startup came during one of the walks with my grandfather in my second year of college (~2011). He used to get tired unexpectedly sometimes and we’ll need to head back to home as soon as possible afterwards. However, sometimes we would be in the middle of nowhere and I would have a hard time getting an auto-rickshaw to go back. Since it was not possible to walk till the nearest rickshaw stand (which could be 1-2 kms away), we would have to wait till an empty rickshaw passes by. This could take 15 minutes to half an hour at times.

This was an obvious inefficiency. Rickshaw drivers were sitting idle in their designated stands while prospective customers spend so much time waiting for them in the near vicinity.

Creating the MVP

I participated with couple of my friends for an hackathon (55444 hackathon by Innoz) in Bangalore in 2011. We created an ‘SMS app’ PoC of the idea which works as follows:

  1. You text your “<source>*<destination>” to our number
  2. We find the closest rickshaw near the source (using Geocoding using Google Maps API).
  3. We reply back with the contact number of the driver

We were selected as one of the top 10 apps shortlisted for the final round of the hackathon. However, the PoC was pretty crude and had many practical limitations and flaws.

400461_524438700905400_1027762657_n
At the Innoz hackathon (2011)

In the beginning of our third year at college, IEEE Communication Society Kerala Section partnered with Startup Village to support select student projects financially and through expert mentoring. Me and my friends submitted 4 ideas, of which ‘SMS Vehicle Locating Solution’ was selected.

At that time, most rickshaw drivers did not have smartphones. One of our primary design constraints was to support such drivers (and customers) through the use of SMS and geocoding. We had multiple design reviews over the next one year which helped us further refine our idea. The funding helped pay for our domain/hosting costs, SMS gateway costs etc.

At the end of third year, I had an opportunity to intern at TEC (Technology Entrepreneurship & Commercialization center), Ohio State university through LabX and Startup Village. I came off really inspired and wanted to do something really impactful.

We decided to register a company and productize our ‘SMS based vehicle locating’ ideaWe started building a customer facing mobile app and website for the service. We initially fixed on the name ‘EasyAuto’ but realized that a similar offering had tried and failed in Bangalore couple of years back. We finally ended up registering the domain ‘findauto.in’ and a partnership firm ‘Smart Transit Services‘ (me and my friend & co-founder Venki as partners). WebOpx, a design startup from our college, designed the ‘findauto’ logo for us.

My classmate Rajath Thomson created the following really nice and short explainer/promo video for us:

In preparation of our launch, we started traveling all around Trivandrum in our bikes talking to rickshaw drivers and ‘onboarding’ interested drivers on our platform. We managed to sign up about 250 drivers.

Screen Shot 2018-01-05 at 11.14.31 PM
A pamphlet we distributed to all drivers (written in Malayalam)

The launch

We knew that our product adoption suffered from a chicken-egg problem. For drivers to be active in the platform, they need frequent trips. For customers to use the platform, they need to get connected to drivers when they make a request.

To jump-start the system, we came up with an idea – a full blown public launch function with media coverage. We will get a surge of customer trip requests which will engage the 250 drivers signed up with us. That will start a virtuous cycle which pulls in more drivers and customers as it goes.

We started reaching out to a lot of celebrities to participate in our function. There were many turn downs initially. However, with the help of a few contacts we managed to get Dr. G. Madhavan Nair (Former Chairman, ISRO) and Shri. Maniyanpilla Raju (popular film actor) to be our Chief Guests. I’ll always be indebted to their kindness.

We booked a hall at Press Club in Trivandrum, where top political or celebrity figures usually address the Press.

We got Syam Annan, who used to run a photocopy center near our college and drive auto-rickshaws part-time to volunteer for a real-time demo of service at the launch function. We also got senior members of the IEEE Kerala Section fraternity to participate in the function. The launch went smoothly.

Post Launch Reception

Our plans seemed to be working initially. A lot of newspapers and websites covered our launch story. We started getting many requests for trips from customers.

First successful trip
Our first successfully completed trip

However, we found that our drivers were not responding to those customer requests. In the spirit of doing things that don’t scale initially, we started manually calling drivers and trying to connect them to nearby trips. We also released a quick update to our service through which drivers didn’t need to reply via SMS, but could simply give a missed call to our number to show their willingness to accept a trip.

Still, we could not get our drivers to respond to customer trip requests. After couple of weeks of unfulfilled trips, our customer requests also started fading away.

EasyAuto

Our college ended couple of months after our launch. Everyone in the findAuto team started joining different companies based on their campus placements. The company suffered a silent death.

However, me and Venki did not give up. We were in touch with the EasyAuto team who had attempted a similar service in the past. We decided to partner with them to try and launch the service in Bangalore with the addition of a smartphone application for drivers so that we have GPS based tracking etc. available in services like Uber.

Screen Shot 2018-01-06 at 12.34.07 AM
EasyAuto logo

We had incubated our company in our college incubator and had secured office space. With the help of my brother Rohith who also came onboard, we hired a full time developer (our classmate Mithun) and also managed to get 3 interns (Joseph, Pratyush and Rohith KP) from our college itself. They started working on the driver side app. We also integrated with a telephony service (KooKoo) in order to bridge the call between the driver and the customer without either party having to share their numbers with each other, in the interest of privacy.

 

IMG_20140823_205257
Smart Transit Services team at our incubated office space in CET

We were planning to launch in Bangalore sometime in December 2014. Our driver app was nearing completion. I would travel on some weekends from Hyderabad to Bangalore to catch up with Venki and the EasyAuto team. However we faced challenges in acquiring drivers in Bangalore. We tried talking to the rickshaw union leaders in order to get their support. One of them asked us for a bribe of 10 lakhs in order to extend his support. We did not have that kind of money to spare nor the inclination to support that.

The final nail in our coffin was put by Ola Cabs, when they announced that they are extending their platform to support rickshaws as well, in early December 2014. They had millions in funding. They were offering each driver 50 Rs. on top of regular fare as incentive to complete the trip. They were also discounting the customer’s trip cost in order to drive adoption. We realized that we didn’t stand a chance. We finally pulled the plug on the idea then.

Overall, though we did not end up achieving what we set out to do, there was immense learning for everyone involved. Apart from the technical aspects of mobile and web application development, I also learned the challenges in co-ordinating and guiding a distributed team towards building a product on time, challenges in customer acquisition etc. It was a really fun ride. 🙂

 

Startup Diaries – Hedcet

Many people have asked me about my startup interactions over the course of the years. I plan to briefly talk about the different ventures I had co-founded or helped out in this series of posts.

Why?

Apart from the reason I just stated above, there are mainly two reasons which motivate me to write this series of posts.

Learnings

Entrepreneurship is a space where there is a lot of Survivorship Bias (link). People mostly hear the stories of the ones who succeed whereas over 99% startups fail. I see that many startups still make those same mistakes that we went through. I would like to document our learnings so that others and (more importantly?) future-me can learn from these.

Remembrance

Having said that, I strongly believe we did many things right too. Some of the same ideas which we tried out were later validated by others (the stories of which I hope to touch upon in this series). But many a times, some of the variables that control the fate of a startup are beyond your control (right place at the right time?). This series is not just about calling out our mistakes, but telling our stories as it is. These were some of the best and most exciting moments in my life.

HedCet

241556_463904833649600_140858337_o
Team HedCet (early 2012)

The year was 2012. I had learned the basics of web development and was looking for an opportunity to use the skills. I came across CampusLAN – an SMS based facility through which students could get to know their attendance instantly. It got popular pretty fast as it let students take an informed decision about bunking classes. It was started by some of my seniors. I immediately got excited and decided to join the team.

At that time, HedCet was a 4 member team. During the course of the next year, we grew to over 10 members. The team composition was interesting in that it consisted of students doing undergrad in Mechanical, Industrial, Electronics, Civil etc along with one or two Computer Science students. Most of them were self-taught programmers. We were coding in PHP using CodeIgniter framework.

We were all heavily inspired by Mobme ( a tech company that was founded by our super seniors) and Startup Village, a non-profit startup incubator that they started. We actively participated and helped organize ’30 days to freedom’, a education policy change favoring entrepreneurship.

30days_to_freedom
One of the promotional posters for 30 days to freedom

And yes, the name ‘HedCet’ did not have any particular meaning to it apart from CET standing for our college (College of Engg., Trivandrum).

Up next, I will try to talk through some of the ideas that we tried out back then.

Avocado

Our plan was to expand campusLAN (rebranded as Avocado) into a full fledged campus management software, with break-through features like fingerprint based attendance marking, social networking features for sharing study materials (dubbed Resource Pool) etc.

Screen Shot 2017-09-27 at 7.07.40 AM
Our press release

We spent about 8 to 10 months developing the software before starting approaching colleges. I remember reaching out to and also traveling to multiple colleges across Kerala trying to talk to the Principals and Head of Departments and convince them to use our product.

We were woken up to a stark reality. All the colleges (including our own) declined our proposals siting various reasons (not feeling the need, opposition to transparency and sometimes even political). Interesting thing to note here was that not even a single college cited a technical reason or lack of some feature to be the reason for declining.

Learning: Test your assumptions early on.

We could have created an MVP fast (in a month or so) and got the same feedback without wasting 10 months of a 6 member development team.

TinyMail

Looking back, I feel that TinyMail was one of our most brilliant ideas. Even though none of us had smartphones or were aware of WhatsApp at that time, our idea was very similar to the modern day WhatsApp.

The idea was this – We already have everyone’s mobile number in our contacts. However email addresses of much fewer people. Why not make your mobile number your single point of communication (i.e. your email address?)

Instead of creating a chat server, we somehow stuck to email. Users need to sign up like normal email but by giving their mobile number. The email address will be <mobile-number>@tinymail.com (e.g. 1234567890@tinymail.com). We setup our SMTP server and had a working website and hybrid mobile app (albeit crappy).

We never really thought that a single easy ‘point of contact’ was in itself a complete product. In the subsequent iterations, instead of improving our UX, customer adoption etc., we tried to create a superior email product with features like an app-store (codenamed SuperMail). We never got any adoption and the product died.

Learning: Focus. Don’t try to do everything. Do one thing really well.

MovieAlerts

At that time, there were no movie booking websites or mobile apps. Considering the limited smartphone adoption in Kerala at that time, our idea was to create an SMS based movie booking platform.

Screen Shot 2017-09-27 at 7.13.04 AM
Yes, we rebranded to vCompile Innovations at one point

We approached the Kerala Film Distributors Association with a proposal to implement this across the various theaters in Kerala. We were met with a lot of bureaucracy and the project never took off.

The problem was eventually solved by BookMyShow across India. Its story is also inspiring in that the founders met similar failure in adoption early on but persisted for many years before becoming a multi-million dollar company and the single dominating movie-booking platform in India (read more here).

Learning: Don’t let a few rejections make you doubt the merit of your idea. Keep persisting.

Other Ideas

We tried out a bunch of other ideas also.

Near Field Communication – 2012 was predicted to be ‘The Year of NFC’. We got a few NFC chips and two BlackBerry smartphones from Startup Village. We made a few basic mobile apps using these. We approached some of the 5 star hotels in Kerala offering to make their hotels/resorts ‘smart’ using NFC.

NFC did not pick up. Our proposals were not accepted.

MediCol – Appointment scheduling and telemedicine services. These are probably still unsolved problems to some extend (at-least in India). We tried approaching some hospitals to adopt our appointment scheduling software. Here also, most of them sited non technical reasons for declining our proposal.

Smartphone games – We tried building some mobile games during that time (ScoreLoop, Tripped etc). We never really ended up releasing a fully functional game if I remember correctly.

As I mentioned, some of these ideas had great potential. We were just in the wrong time, wrong place or didn’t have the right resources to execute these. It’s always easier to look back and identify your mistakes. Identifying the ones you’re yet to make is an all together different ball-game.

Nonetheless, I am sure the whole team learned a lot and moreover enjoyed a lot during this period. At the end of the day, probably that’s what matter?

Update: One technical learning that I forgot to mention was the importance of version control. As a five member dev team, we used to have five versions of our code base in a shared Dropbox folder. Substantial amount of time was wasted in keeping these in sync and merging changes together.

I strongly recommend version control (Git preferably) for even a one person single day project.

Introduction to Information Security – Experience

I did the Introduction to Information Security course (CS6035) as part OMSCS Summer 2017 semester.

The course was a good overview of various aspects of Information Security. It broadly covered topics like system security, network security, web security, cryptography, different types of malware etc. The course was lighter in terms of work load compared to the other subjects I’ve taken so far. I really liked the projects which were thoughtfully designed to give the students hands-on experience in each of these topics.

The four projects that we had to do were:

  1.  Implementing Buffer Overflow in a given vulnerable code. This required brushing up on C basics,  understanding how process memory allocation works internally and some playing around with gdb.
  2.  Analyzing provided malware samples using Cuckoo, an automatic malware analyzer and sandbox to identify behaviors such as registry updates, keyboard and mouse sniffing, remote access, privilege escalation etc.
  3. Understanding and implementing the RSA algorithm in python, identifying the weakness in using smaller length keys (64 bit) and decrypting an RSA encrypted message by exploiting this weakness.
  4. Exploiting vulnerabilities in a target (sample) website using Cross-Site Request Forgery (XSRF), Cross Site Scripting (XSS) and SQL injection.

Apart from the projects, there were 10 Quizzes to be completed, one per week throughout the course. The various exploits discussed in the course are fairly easy to be introduced in a codebase if you are not aware of these. Unfortunately, these are pretty common even now, many years after they were first discovered.

Hence, no matter the type of software development one is into (mobile, web, DB, relatively low level languages like C, embedded device programming, bare metal etc.), these exploits and their counter-measures are a must-know.

 

Reinforcement Learning – Experience

I completed the Reinforcement Learning course (link) as part of OMSCS Spring 2017 semester. It was one of the most rewarding courses I took as part of the program till date.

The course was taught by professors Charles Isbell and Michael Littman, the same Profs who had taken the Machine Learning course previously (blog link). The course was really challenging considering the closely packed and research oriented home works and projects as well as the math/theory heavy course material. We had

  • 6 home works which involved implementing different RL algorithms to solve given problems
  • 3 projects out of which two were the reproduction of experiment results from prominent RL research papers and one was solving an RL problem using OpenAI Gym

Summarizing my key learnings from RL below:

  • Reinforcement learning helps you train an AI agent to maximise some form of reward without prior understanding of the environment  -i.e. model-free.
  • E.g: Pacman. Here the agent (or player) can roam around the space using possible actions (left, right, up, down). When it consumes one of the small orbs, it gets points (+ve reward). When it eats the big orbs and then eats the enemy players, it again gets more points. However, if it’s eaten by one of the enemy players, it loses a life (-ve reward). If you let an RL agent play Pacman for some time, it will start playing randomly, but eventually, figure out the rules of the game and can potentially play better than a human player. All this without we injecting any domain knowledge (rules of the game, winning strategies etc.) beforehand! (crazy right?)
  • Screen Shot 2017-05-07 at 10.23.36 PM
  • Most RL research assumes all processes can be represented using MDPs (Markov Decision Processes). These are processes where the entire past can be represented using the current state of the agent.
  • Learned about different RL algorithms such as:
    • Value Iteration
    • Policy Iteration
    • Q-learning
    • TD-Lambda etc.
  • Generalization using function approximation – This seemed to me to be one of the most promising sections of RL. It can effectively take RL outside the confines of Grid world and into the big and continuous state spaces of the real world.
    • For one of our projects, we used DQN (Deep Q-Networks), one of the latest efforts in generalization using deep neural networks, published by DeepMind – a Google company.
  • Reward Shaping – a mechanism to accelerate the learnings of the agents and help them get to their goals faster.
  • POMDPs (Partially Observable MDPS) – These are closer to the processes which we see in real-life. We don’t get to know fully which state we are in. We have to work with a set of ‘belief states’ or probability distributions of possible states we might be in.
  • Game Theory – I found this to be the most fun part of the course. It deals with stochastic games where multiple agents try to maximise their collective/competing rewards. This is again closer to the situations which we face in real-life. Topics include:
    • Prisoners Dilemma
    • Nash Equilibrium
    • Folk theorem and sub-game perfect equilibrium
    • Tit-for-Tat, Grim trigger, Pavlov etc. game strategies
    • Coordinated equilibria, using side payments (Coco-Q) etc.

The course content was a bit too theoretic in some chapters (e.g.: AAA – Advanced Algorithm Analysis). I found lectures from David Silver, DeepMind to be a good supplementary course to build the required intuition for this course – link.

One of the really exciting moments in this course was when Prof. Richard Sutton, considered by many as the father of Reinforcement Learning, and the author of the primary textbook for RL (of our course and elsewhere) ‘Reinforcement Learning: An Introduction’ (second edition draft available from author’s website – link) appeared for one of our office hours as a special guest.

Screen Shot 2017-04-20 at 4.44.15 AM
Prof. Richard Sutton along with our TAs during an office hour

I found all the TAs for this course really knowledgeble and helpful. All the office hours were really useful and fun-filled at the same time. One of our TAs, Migual Morales has been featured in the OMSCS website recently – link.

In conclusion, this course has been one helluva ride that I enjoyed throughout! 🙂