Monday, 20 May 2013

Start-ups & Growth

I've been spending a lot of time exploring the start-up scene here in NYC. I've got my own, GoFest, that I'm nurturing. I've also been looking to get involved in another. Finding a team with the right mix of people and doing something that fits for you is difficult. As I've been exploring and searching for a start-up to join, I've been learning more about evaluating their business models for risk and potential success. There are lots of angles to come from in doing this, but I've found the easiest is to root everything from the most important central point. Growth.

It seems unanimous that what makes a start-up a start-up is growth. It must attain and maintain (while it's market/infrastructure allows) rapid growth. In this post (whose primary sources are The Lean Startup and Paul Graham) I will examine the definition of a start-up from the view point of Growth. In doing so, I'll cover a number of topics that I've found foundational.

  1. The types of business models capable of rapid growth.
  2. What does this growth look like? How long must it be maintained?
  3. How is it defined? Revenue vs user-base.
  4. Targeting and strategizing to reach rapid growth.

Let's look at these one by one!

Business Models Capable of Rapid Growth


Lots of businesses are started each year.. only a fraction can achieve the rapid growth start-ups aim for. What sets them apart? There's a definitive difference in the business model. For a business to achieve the rapid growth of a startup, it must do, at least, these two things.
  1. It must make something many people want.
  2. It must be able to reach and provide that something to almost all of the people wanting it.
How do startups achieve both of these? Frozen yogurt has recently exploded in popularity. Does selling frozen yogurt equate to a start-up? People everywhere are demanding more frozen yogurt. That satisfies #1. Opening a frozen yogurt shop around the corner from your house doesn't mean you can reach and serve everyone who wants to buy frozen yogurt, however. You will be limited to those who can and are willing to come into your frozen yogurt store. So, businesses like these do not satisfy #2 of the above criteria.

This is why businesses like Etsy, Pinterest and many more have been tagged as super successful startups. They are able to reach anyone who wants to use their service (and has access to the technology that enables them to do so - PC, mobile phones, etc..).

One further thing to note here is that rapid growth is enabled because each new customer who receives service should be, relatively, cheaply acquired. Your infrastructure must support each new user. But, as with Etsy and Pinterest, this can be done in an automated fashion where each new user takes minimal if not zero human interaction. There are still start-ups where this price is not as cheap. If you're selling tangible products you must have the inventory and the workforce to stock, package and ship the items you sell. Allowing for rapid growth with these businesses can be a bit more tricky, to scale things efficiently, but these are still start-ups if they can manage it. (Examples of this are Amazon or many of their acquisitions. Zappos, Endless, etc..)


What is Rapid Growth?


Understanding the business models capable of becoming startups helps to define what this rapid growth looks like. It seems that start-ups go through some pretty standard stages.

  1. Initialization. This is the declaration of intent to start a company and the initial work to lay some framework in place and get the right team of people together. There's probably not yet a customer-base at this point, so growth is typically zero.
  2. Product development. This is where growth is important. If you follow the Lean Startup methodology (the bible for startups) you should be getting an MVP in front of customers as early as possible and begin getting feedback. If you use this feedback to drive your product development, you'll hopefully see customer growth during this phase.
  3. If product development goes well, and something is built that customers love, a business can grow into a large company. It's when a business/business model reaches the limits of it's market or infrastructure capability that growth could start to slow. 
Reaching the final stage doesn't mean the end of growth. It may for a particular product or business model. But, this could be the point when more innovation happens and new markets/products/services are developed. The cycle can happen all over again!


Revenue versus User-base


This question would not have come up 10 or 20 years ago. Previously, a business MUST define their growth by revenue. If it wasn't making money, it wasn't growing. Today, there are more options.

Again, growth rules out. Because rapid growth is only possible by expanding your user-base, it is debatable about whether this should be prioritized over revenue or not. It seems that today, loyal non-paying users are valuable. Facebook has 80 million users. These users are extremely accessible for any contact Facebook wishes to make. This is valuable. Facebook was valued at $104 billion during it's IPO. While Facebook has yet to capitalize on it's user-base, there is trust that there is money in this model.

Still, a strong revenue model should be at the foundation of your business model if possible. The short customer feedback loop returns here. Testing out how to charge for you product or service as it's developed is the path to success. You can determine which features customers are willing to pay for and which one they're not.


Targets and Strategizing


These feedback loops with your customers are what should drive product development and inevitable drive your growth. This is how waste is reduced. If you're building something that customers love it is a success! If you're building something they don't want, it's best to find out as soon as possible. Get it or at least a minimum version of it in front of them as soon as possible. And find out if they think it's valuable or if your assumptions about how they'll receive it are correct.

If you can fake a feature to get customer feedback sooner, do it! I particularly liked the Zappos case study used in the Lean Startup around this topic. Instead of building a complete online shoe store, together with inventory, the founder of Zappos got permission from local shoe stores to photograph their stock. He put the photos online to find out if people were willing to buy shoes over the internet. (A core assumption in his business model.) For each purchase he would go to the store and buy the shoes, mailing them to the customer. This is not a sustainable model.. but it proved that people would buy shoes online. Valuable customer feedback. He could them move on to the next assumption that he needed feedback on, learning from the interaction with his customers as he went.

The take away is to, again, let growth drive your progress. Target the growth of your customer-base and the revenue it generates in the decisions driving your product development. If you take things in one direction and see no growth, it may be time to try something else. (The pivot! - as stated in the Lean Startup.)

In conclusion


This is all really just scratching the surface on this topic. After reading the Lean Startup and several of Paul Graham's posts on the topic, I really liked the idea of basing all thing on Growth. It's easy to ask at each decision-making point. Will this lead to growth? How can we test that quickly?

Tuesday, 9 April 2013

Heroku Dyno-wha??



I've been using Heroku for a few months to host rails app that serves as the backend to a iOS app I've been working on. Heroku has been awesome because it's incredible easy to deploy your web app to a production environment seamlessly.

How does all of this work behind the scenes, however? Let's start with what Heroku calls the 'basic unit of composition'.

Dynos


These are essentially each a virtualized Unix container. You execute commands against them. They start out with a default environment (Heroku's Cedar stack). When your app gets installed onto one of these (as a slug.. more on this later!) commands are executed against it based on your app and it's dependencies.

Web vs. Worker dynos

Web dynos serve web requests. If your web requests trigger things like fetching data from remote APIs or uploading data to S3, these can potentially tie up your web dyno. Worker dynos come in here. You can use a strategy that delegates these processes to a job queue and worker dynos will pick things up from this queue. 

So, how do you scale these two types of dynos?
  • Use more web dynos to support more concurrent users
  • Use more worker dynos when your job queue starts getting backed up.

All manual activity like console sessions, or rake tasks trigger a 'one-off' dyno where they run in isolation. This includes all of your 'heroku run' this or that commands? 

The Job Queue

This image is a good visualization for how it works.



Backgrounding tasks or processes is a concept. Heroku doesn't define how to implement this. With RoR, I've used Resque successfully.

If the user request that triggers the job needs to await the response, you do need to come up with a strategy for getting it to them when the process finishes. Polling to see when their job has finished is generally acceptable.

Dyno Management

What manages these different dynos and makes sure they're in sync? Heroku uses it's dyno manifold to do this. When you deploy new code, all of your app's dynos are restarted. The dyno manifold also monitors your dynos for errors or issues and restarts or moves them accordingly. I think the way the dyno manifold is implemented is one of Heroku's secrets as I haven't been able to find documentation anywhere. They do say that it coordinates your dynos, manages the programs that operate your app and generally allows you to remain hands-off in how it works.

Slug Compilation

When you git push to Heroku, the code is received by the slug compiler. This transforms your repository into a 'slug'. These are precompressed and pre-packaged copies of your application optimized for distribution by the dyno manifold. When you scale your application by increasing web or worker dynos, these slugs are distributed and expanded on each new dyno as well.

Dyno Idling

One thing you'll care about immediately after beginning to use Heroku will be the dyno idling policy. If your app has only a single web dyno running (this is the default and free option), it will idle out - irrespective of the number of worker dynos. This means that if you have no web requests for 1 hour, your app is effectively put to 'sleep' (idled). 

Subsequent requests to an idled app will result in the dyno manifold for the app being signaled to unidle or 'wake up' your dyno. This can result in a delay of up to 15 seconds... sometimes longer. Pretty annoying and incentive to increase your number of web dynos to ensure one is always there to receive a request.

Check out the Heroku documentation for dynos as well. This is where I got most of my information!

Wednesday, 20 March 2013

Multiple MOCs - Why?

I've been using Core Data with my current iOS app since early days. I've been learning more and more about the idiosyncrasies of Core Data and this magical thing called the 'Managed Object Context'.

What is the Managed Object Context?

I've heard it described as a scratchpad for you persistent data store. You can use it to represent the current state of your data store, or it can function to hold temporary data... that won't be or hasn't yet been persisted to your data store.

I think knowing these functions and thinking about them when you first start working with Core Data and managed object contexts is important. Otherwise, you ask yourself... 'Why, do I have to go through this thing to talk to my data store'.

After you understand this, you might ask yourself.. 'Well, why do I need to hold temporary data..? Or hold data before persisting it?'

I know of few cases where this is useful.
  1. Entity creation that spans multiple screens. As a ex-web developer I can think of what a pain it is to do this in the web world. If the user cancels half-way through, you need to ensure that nothing has persisted to the database. In web, you would have to have some fancy javascript or session storage going on to make this work. It's a huge pain! If you use something like an MOC to store this temporary object while the user builds it out, you don't have to persist it until it's completed.
  2. Data synchronization. Consider a situation where the user creates some entity that needs to be persisted to a back-end server. One strategy for doing this involves hold that entity in an MOC and only merging it to the main MOC and underlying data store when it has successfully been persisted to the back-end server.
I bet there are lots of other useful ways of using multiple MOCs. I'm just starting to explore this realm of Core Data and will update this post if I find other use cases!

Tuesday, 12 March 2013

Property Attributes and Definition in iOS

Properties are an alternative to defining instance variables and their corresponding accessors methods. Let's go over the difference

Defining a Property vs. an Instance Variable


Without Properties

With Properties

What happens behind the scenes here are declarations for you accessor methods. This means with the above header and implementation code, you can operate on an instance of this object as follows.

Property Attributes


Each property has a set of attributes that describe the behavior of the accessor methods for that property. Here's an example.

There are three property attributes. Two of these must be specified and the 3rd has a default.
  1. The first attribute specifies either atomic or nonatomic. This has to do with multi-threading. Let's just say here that if you're doing a standard iOS app you should be using nonatomic.
  2. The second attribute specifies either readwrite or readonly. This tells Objective-C whether it should generate a getter and a setter(readwrite)... or just a getter(readonly).
  3. The final attribute has to do with memory management, which I've talked about in more detail here. The options here are weak, strong, or assign. Assign is the default which can be used for primitive values that don't point to an object. (like int)

iOS memory management with ARC

I've been learning iOS development over the last few months. I've been lucky enough to be working with iOS's ARC or automatic reference counting. This is what was introduced in iOS 5 and makes life a lot easier for iOS developers.

To understand how ARC works, a few concepts involving application memory need to be considered.

The Heap

This is the part of memory where all Objective-C objects are stored. When you send the alloc as a message to a given class, a chunk of memory is allocated from the heap for this new instance. This chunk includes space for the object's instance variables. However, if these instance variables are references to other objects, those objects are stored in their own heap allocation.

Pointers are used to remember where objects are stored in the heap.

The Stack

If the heap can be visualized as a heap of objects we reference via pointers, the stack can be visualized as a stack of frames (or chunks of memory). Frames from the stack are allocated as methods are executed and they store variables declared inside the method (i.e. local variables).

If you think about it. Most programs start by running some sort of main function. This would be the first frame on the stack. If it calls another method which then calls another method... each of these would get new frames allocated from the stack. As each method finishes, it's frame is popped off the stack and destroyed.

Pointers

These point to objects stored in the heap.

These can exist in 2 forms:

  1. As references from the local variables defined by methods using frames on the stack.
  2. As references from instance variables on another object stored within the heap
Memory Management

Heap memory is obviously not endless. It is important to destroy objects that are no longer needed to make room for new objects. It is also very important to not destroy objects that are STILL needed.

Object ownership is what helps in determining whether an object should be destroyed or not.
  • An object with no owners can be destroyed
  • An object with one or more owners can not be destroyed
iOS's ARC

Automatic reference counting was introduced in iOS 5 and takes care of deciding which objects have owners and which don't. And destroys those that don't! Before this, you would have to manage memory yourself using retain and release messages.

ARC now takes care of most of this for you, but it's still important to know what's going on behind the scenes in case you need to step in at some point.

How does ARC know an object doesn't have any more owners? It keeps track of all pointers to that object as they are created. Later, a number of things can happen to these pointers which mean they don't 'own' the object at the other end of the pointer.
  1. The pointer is changed to point to another object
  2. The pointer is set to nil
  3. The variable holding the pointer is destroyed
The last one is interesting because, as objects own other objects, which can own other objects.. the destruction of a single object can set off a chain reaction of loss of ownership and subsequent object destruction.

Your Hook in ARC

In Objective-C you're able to define variables as having strong or weak references. This ties directly into how ARC will manage the objects pointed to by these variables.

Strong Reference - This encompasses the discussion so far. If a variable is defined as pointing to an object, that object will never be destroyed.

Weak Reference - A variable that does not take ownership of the object it points to. If an object only has pointers from weak references pointing to it, it will be destroyed

Why have weak references? They're mostly used for retain cycles. This is when two or more objects have strong references to each other. This is bad because neither of these (or any objects they own) will ever be destroyed, even if all other pointers to both have been removed.

An interesting thing about weak references is that they know when the object they point to is destroyed. They are set to nil in this case. This will prevent any exceptions from occurring if the object containing that weak reference ever tries to use it.

Conclusion

So, if all those strong vs. weak variable definitions were confusing you (as they did me at first) there you go. It's the framework for memory management in Objective-C.

Monday, 4 March 2013

AF Networking Simplifies iOS Http Requests

I wrote this post a month or so ago on implementing http requests using the built in iOS libraries. I've been building a iOS app with a Rails on Mongo instance functioning at the backend API. I just switched everything over to AF Networking, which has helped simplify my network calls greatly!

If you compare these two approaches you can see the simplicity AF Networking gets you!

And then you just implement the two methods given to the networking operation callback block. In this case, processResult and processFailure. It's so simple! And so much less code than the standard iOS option.

The AF Networking github page.

Monday, 25 February 2013

iOS Data Synchronization - How???

I'm working on an iPhone app at the moment and I'm approaching the time when I'll need to do data synchronization with my backend Rails API. Up to this point, I've only pulled data down to the mobile device so the backend has acted as the sort of 'master' of the data. Now, data entered on the device will need to be incorporated into the 'master' data and available to all users.

I've sort of been deferring the decision of how to implement this until the last 'responsible' point because it's a daunting task... and done wrong, would perhaps need to be completely done over again in the future.

I remember the pain on my last project (an Android tablet app) after we brought in our first solution to data syncing between device and backend. We suffered through 3 months of headache and then gutted the whole thing for another strategy. The odd thing is the initial thing we'd gone for was one of the Android 'recommended approaches'. These things called Cursor Adapters. Steer clear! I'll maybe do a different post on these and why they are painful.

So, I'm cautious about using libraries intended to be a one-size-fits-all. Luckily I guess, I haven't actually found any for iOS, so I think I'll be rolling my strategy.

These are the questions I'm asking myself.

1. How close are the data models between the device and backend?
2. How much data will be need to be synchronized?
3. How frequently will it need to be synchronized?
4. If the user deletes the app and reinstalls it, will data need to be downloaded to the device in the same state as before the delete?
5. I'm going to need to know which data came from which user.. how will I tag the data as such?
6. How to queue up changes if they are made while the user if offline?

Because I don't have a huge amount of data that will need to be synched, my initial approach will be to set up a process that checks for changes across the tables where they might occur (initially only 2 for my case) and then pushes these to my RESTful backend using JSON over an HTTP post request. My backend, will then store these data in separate tables where the user and timestamps are recorded. After this, I should be able to set up another timed request. More posts as I move forward on this!