Thomas Griffin https://thomasgriffin.io 1
Using WordPress as a SaaS PlatformBy: Thomas Griffin (@jthomasgriffin)
Thomas Griffin https://thomasgriffin.io 3
I am a partner and CTO of Awesome Motive, Inc. and the technical Co-Founder of OptinMonster. Prior to OptinMonster, I founded Soliloquy, the fastest WordPress slider plugin, and Envira Gallery, a revolutionary gallery solution for photographers. I also built TGM Plugin Activation and serve over 30,000 happy customers.
Thomas Griffin
Thomas Griffin https://thomasgriffin.io 4
To improve is to change; to be perfect is to change often.
!
"
Winston Churchill
Thomas Griffin https://thomasgriffin.io 6
The OptinMonster Timeline
We meet to discuss the awesomeness that would become OptinMonster.
OptinMonster is Born
We failed to build a SaaS model, so we pivoted to a WordPress plugin. Totally worth it.
OptinMonster Launches
We moved from an MVP to a rock-solid v2.0 release, building a very feature-rich platform with even better technology.
OptinMonster 2.0 Lands
Our customers are demanding solutions outside of WordPress, so we hit the ground running building the hosted platform.
OptinMonster…SaaS?
Jan. 1, 2013 Sept. 24, 2013 Aug. 24, 2014 Oct. 8, 2014 May 5, 2015
The OptinMonster hosted platform launches, allowing OptinMonster to be used on any website.
OptinMonster App
Thomas Griffin https://thomasgriffin.io 8
Epic Considerations•Data Migration •Scaling •System Architecture •Security •Payments •Onboarding •Support •Caching •High Availability and Redundancy •Interfaces •User Experience •Development Workflow
Thomas Griffin https://thomasgriffin.io 10
Over 7 billion requests served since 2013.
Thomas Griffin https://thomasgriffin.io 11
500 million requests served last 30 days.
Thomas Griffin https://thomasgriffin.io 12
5 million leads generated in last 30 days. (That’s a bunch of requests to email service providers)
Thomas Griffin https://thomasgriffin.io 13
And WordPress handles all this??!?!?! YES!
Thomas Griffin https://thomasgriffin.io 15
Database
•InnoDB preference over MyISAM •add index to wp_options autoload •use persistent object caching with Redis to prevent extra queries
Thomas Griffin https://thomasgriffin.io 16
Users
<?php wp_*_current_user() *_user_meta()
•start with simple subscriber user, strip permissions, add caps from here
•custom data keys for account access using user meta
Thomas Griffin https://thomasgriffin.io 17
Optins
•custom post type for handling each optin •custom data storage using JSON (https://thomasgriffin.io/wordpress-performance-outside-box-handling-retrieving-data/)
•custom AJAX requests for saving and generating data •public output generated at save and update intervals for performance
Thomas Griffin https://thomasgriffin.io 18
API Requests
•scaling API requests (https://thomasgriffin.io/a-creative-approach-to-efficient-and-scalable-wordpress-api-endpoints/)
•this solution works for admin-ajax.php requests too! (https://gist.github.com/thomasgriffin/11b859f0531a812bb273)
Thomas Griffin https://thomasgriffin.io 19
API Requests<?php /** * Plugin Name: Custom admin-ajax.php Helper * Plugin URI: https://thomasgriffin.io * Description: Whitelists the plugins to be loaded during admin-ajax.php requests for performance. * Author: Thomas Griffin * Author URI: https://thomasgriffin.io * Version: 1.0.0 */ !// Check against the request URI. if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { return; } !// If it does not match the admin-ajax.php route, do nothing. if ( strpos( stripslashes( $_SERVER['REQUEST_URI'] ), 'admin-ajax.php' ) === false ) { return; } !// Ok, this is an admin-ajax.php request. Filter available plugins. add_filter( 'pre_option_active_plugins', 'tgm_whitelist_admin_ajax_plugins' ); function tgm_whitelist_admin_ajax_plugins( $plugins ) { ! // Only modify the ajax requests performed by our own plugin. $action = isset( $_REQUEST['action'] ) ? stripslashes( $_REQUEST['action'] ) : false; if ( ! $action ) { return $plugins; } ! // For this example, we will target the heartbeat ajax request. if ( 'heartbeat' !== $action ) { return $plugins; } ! // Prevent any plugins from loading during the request. $whitelist = array( // my-custom-plugin/my-custom-plugin.php ); ! // Return the whitelist instead of the default plugins. return $whitelist; !}
Thomas Griffin https://thomasgriffin.io 20
Caching
•literally cache everything with persistent object cache (preferably Redis) and fastcgi cache with Nginx
•this makes 99.9% of requests hit cache •minimize impact of non-cache hits to DB
Thomas Griffin https://thomasgriffin.io 21
Infrastructure
•we love Pagely! •custom setup on AWS using ec2 load balanced instances, RDS (database), Route 53 for DNS, Elasticache w/ Redis
•smart cache purge policy on updates and save requests •utilize MaxCDN for images and API script requests
Thomas Griffin https://thomasgriffin.io 22
Development Flow
•absolutely everything starts on local! •marketing and app site split into two separate installs •staging and production environments •git feature branch dev - (http://nvie.com/posts/a-successful-git-branching-model/)
•custom vagrant boxes for easy dev on boarding
Thomas Griffin https://thomasgriffin.io 23
Support
•all requests through HelpScout - easy ticket sharing, notes, workflows •integrated with Gravity Forms to automatically tag and segment requests
•TONS OF DOCUMENTATION •fuzzy search and user “creates docs for us” •happiness reports to identify trends, ways to improve
Thomas Griffin https://thomasgriffin.io 25
Notifications
•simple notification system for in-app updates •custom post type and user meta to check for view state •pulsing dot to notify users of new notifications
Thomas Griffin https://thomasgriffin.io 26
Jobs and Queues
•daemons and workers to handle intensive, long processes •utilize redis + job queues to prevent server overload •useful for monthly conversion reports, platform data insights
Thomas Griffin https://thomasgriffin.io 27
But the most important ingredient…
Thomas Griffin https://thomasgriffin.io 29
Processes and systems help, but your team makes the difference.
Thomas Griffin https://thomasgriffin.io 31