Building for Success and Failure with AtlantaPHP, October 2014

“Let’s Build a Blog!” Says Every Developer Ever

What is it? • Discussion web service • Free as in beer • Integrates with everything • Quality content • OAuth and SSO • Embeddable widget • Web API

Fundamentals A crash course

Forum Thread Post

Category Limitations • Categories may only be created using the API. • Moderation may not be performed on posts by Category, only by Forum and Thread.

Disqus API threads/create threads/list posts/create posts/list posts/report Full documentation is available at http://disqus.com/api

Registering Your App https://disqus.com/api/applications /register/ 1. Specify Domains 2. Set Permissions Read Read and Write Read, Write, and Manage 3. Save Tokens Access Token API Key API Secret

Create a Forum https://disqus.com/admin/create/ 1. Name your site 2. Specify a unique domain Creating an application does not implicitly create a forum!

Posting to Disqus As a user Authenticate via OAuth As a guest 1. Enable “Allow guests to comment” (Settings > General) 2. Application domain must be set correctly 3. Use the magic API key: E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7 C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F

drexarj/disqus-php github.com/disqus/disqus-php Composer: drexarj/disqus-php

What could possibly go wrong?

Caching to the Rescue

Caching to the Rescue

It’s Dynamic Data… • New posts submitted • Moderator approves post • Moderator disapproves post • User flags a post as objectionable

Conflicting Objectives • High load • • Short cache expiration Failover • No cache expiration • How to synchronize?

Adding a Failover Cache burst cache 1 2 3 failover cache

Failing Over burst cache 1 2 3 failover cache

Adding a Health Check burst cache 1 2 3 4 failover cache

Caching Health Status • If health status expires, everything just fails over • Adjust the health status expiration to back off: • FAIL 1: expiration=2 minutes • FAIL 2: expiration=4 minutes • FAIL 3: expiration=8 minutes • …etc

“Is it worth it?” –You

Implementation: Cache Servers • Burst: memcached • Failover: MongoDB (or Redis)

Implementation: Scripts • Health check • Cache warmup • Thread creation

Implementation: API Client • Guzzle-based client (compwright/disguz) • Custom Guzzle Cache adapters

Building for Success and Failure with AtlantaPHP, October 2014

Thank you! • https://github.com/compwright/disqus-demo • https://github.com/compwright/disguz • https://github.com/compwright/disqus-cli Feedback: https://joind.in/12119