348
Certificate of Good Standing Knowledge Transfer Presentation New PR.gov Infrastructure Good Standing Certificate Service By Andrés Colón Pérez

Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Embed Size (px)

Citation preview

Page 1: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Certificate of Good StandingKnowledge Transfer

Presentation

New PR.gov InfrastructureGood Standing Certificate Service

By Andrés Colón Pérez

Page 2: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About me

• Architect for the Good Standing Certificate System• Office of Management and Budget Employee

previously assigned to the Chief Information Officer Office

• Worked with a multi-agency team to identify the problems and solutions

• Designed and developed the PR.gov infrastructure, networks, applications and deployment automation

Page 3: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About this Presentation

• An attempt to familiarize government personnel with:– building modern digital services– using free open source software to reduce

licensing costs– designing networks, building and deploying

applications– designing scalable government systems

Page 4: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

What you’ll learn over the weeks:• Project Overview (in spanish) • Overview of concepts and technologies used in design, app development,

and infrastructure, including:– HaProxy– Keepalived– Bind9– Redis– Ruby– Resque– Padrino, Grape, Puma, EventMachine and other gems– HTML5 and Twitter’s Bootstrap– Git– Ansible– PhoneGap

Page 5: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Week 1

Knowledge TransferNew PR.gov Infrastructure

Good Standing Certificate Service

Page 6: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

What’s the Plan?

• Overview of Knowledge Transfer Plan• Knowledge Transfer Talk Topics: Week 1

Page 7: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Before we get started:

• Topics serve as an introduction• Feel free to ask questions• You’re expected to read up more on your own• Five minute breaks

Page 8: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

KNOWLEDGE TRANSFER PLAN

Page 9: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Knowledge Transfer Plan

• Weekly Presentations– Save your calendar: Fridays 2:30pm– June to September– Starts June 19, end September 11 2015

• Weekly Q&A, Thursdays 9:30am – 10:30am• Multiple Topics

Page 10: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Week 1 Topics

• Overview of concepts and technologies in:– Development– PR.gov Infrastructure / Network Design

Page 11: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Development Topics

• Software Architecture Style (Micro-Services)• Application Programming Interfaces• Redundancy and Scalability• Asynchronous vs Synchronous Services• Open Data (data.pr.gov) • Version Control • Open Source (Github / Application Stack) • Software Development Method (DevOps)

Page 12: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 13: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

MICRO SERVICES

Page 14: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Monolithic Applications

Page 15: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Monolithic Applications

Page 16: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Monolithic Applications (1990s)

• Tight coupling• Everyone must agree on changes• Each change has unanticipated effects

requiring careful testing beforehand • Harder to Scale

Page 17: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Micro Services (2010s)

• Software Architectural Style• Complex Applications composed of small

proccesses• Loose Coupling• Easier to Scale

Page 18: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Micro Services

Page 19: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

APPLICATION PROGRAMMING INTERFACES

Page 20: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

API’s for Short

• Set of Protocol, Routines & tools for building software applications

• Goal: interoperability• A Web Service is a type of API• Most popular Web Services:– Simple Object Access Protocol (SOAP)– Representational State Transfer (REST)

• SOAP often referred to as WebService• REST often referred to as REST API

Page 21: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 22: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 23: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 24: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 25: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

REST APIs

• Versioning is important– /v1/apiname/resource– /v2/apiname/resource

• Must properly implement HTTP error codes• Commonly return JSON, YML.

Page 26: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

REDUNDANCY AND SCALABILITY

Page 27: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 28: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 29: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 30: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 31: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 32: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 33: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 34: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Handling Load

Page 35: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

ASYNCHRONOUS VS SYNCHRONOUS SERVICES

Page 36: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Synchronous

Page 37: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Asynchronous

Page 38: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 39: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 40: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 41: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Open Data

Page 42: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Open Source

Page 43: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Version Control

• System that records changes to files and set of files

• You can easily recall specific versions• Great for collaboration:– Branch– Merge – Revisions

• Popular version control: GIT, Mercurial • GITHUB != GIT

Page 44: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

DevOps

Page 45: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

DevOps

Page 46: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

DevOps

• Short for Development and Operations• As Systems Scale, automation is critical• Do more with less• Consistent and easily deploy servers, manage

networks and applications

Page 47: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ansible

Page 48: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ansible

• Server Automation for Humans• Based on SSH• YAML Configuration Files• Doesn’t require dedicated server• Uses Playbooks

Page 49: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

PR.gov Infrastructure Topics

• Security Philosophy• Networks Segmentation• Virtual Router Redundancy Protocol• Documentation

Page 50: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SECURITY

Page 51: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Networks in the new Infrastructure

• Why Segmented Networks?• Servicios PR.gov Networks

Page 52: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Why Segment Networks?

• Splitting networks into subnetworks• Boosting Performance• Improving Security

Page 53: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

VIRTUAL ROUTER REDUDANCY PROTOCOL

High-availability

Page 54: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 55: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 56: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

PR.gov Networks

• Public Load-Balancing Network– Redirect Public Traffic

• Front-End Network– Process Public Traffic

• Private Network – Inter-agency and intra-services network

• Back-end Network– Private data storage

Page 57: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 58: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Next week

• VRRP in Linux• Haproxy Load balancer• SSH Authentication

Page 59: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Week 2

Knowledge TransferNew PR.gov Infrastructure

Good Standing Certificate Service

Page 60: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

What’s the Plan?

• Last week Q&A• Overview of Knowledge Transfer Plan Week 2• Knowledge Transfer Talk Topics: Week 2

Page 61: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Last week we saw:

• CAP Project Overview• Overview of concepts in:– Development– PR.gov Infrastructure / Network Design

Page 62: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Last Week: Development Topics Q&A

• Software Architecture Style (Micro-Services)• Application Programming Interfaces• Redundancy and Scalability• Asynchronous vs Synchronous Services• Open Data (data.pr.gov) • Version Control • Open Source (Github / Application Stack) • Software Development Method (DevOps)

Page 63: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

PR.gov Infrastructure Topics Q&A

• Security Philosophy• Networks Segments• Virtual Router Redundancy Protocol• Documentation

Page 64: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Overview of technologies in Operations:

Infrastructure Services:• Keepalived (implementación de VRRP en Linux)• HaProxy (Load-Balancing en Linux)– Introduction– HTTP Load-Balancing– TCP Load-Balancing– Health Checks

• TLS• Key Authentication

Page 65: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

KEEPALIVED

Page 66: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

KEEPALIVED

Page 67: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

KEEPALIVED

Page 68: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

KEEPALIVED

Page 69: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived:

• Definitions• About• Installation• Configuration• Logging

Page 70: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

High-availability

“A system that is continuously operational for a desirably long length of time”

Page 71: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

High-availability Goal:

Page 72: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

High-availability in Servers:

Page 73: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived• Free Open Source Software• Zero licensing costs• Written in pure C• Used for High-availability• Implements VRRP• I/O Multiplexer provides realtime networking• Robust and Stable

Page 74: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived & VRRP• VRRP is IETF protocol• Allows two or more routers to act as a virtual

router• Routers present a Virtual IP Address (VIP) that

corresponds to a Virtual Mac Address (VMAC)• Each router has a real hardware and IP

address

Page 75: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived & VRRP• Linux does not support Virtual MACs.• Keepalived only implements VIPs, works fine

on all modern networks • Requires a network that allows gratitious

Advanced Resolution Protocol (ARP) requests– An advanced notification– Updates cache ARP cache before other systems

ask for them

Page 76: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived & VRRP• Backup Server(s) monitor continuously– Listens for multicast advertisements – Expects them from the current master server

• If master disappears– An election process ocurrs– The highest priority backup wins– Winning backup announces gratitious ARP for that

VMAC, and takes over– Happens almost instantly

Page 77: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived

Page 78: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived: Software Design

Page 79: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

• IP Virtual Server: provides transport-layer load balancing inside the Linux kernel

• Layer-4 switching (OSI)• Allows things Linux Virtual Servers (LVS)– Cluster of servers – Appears as single server to user– Layer 4 balancing

• Note: we dont use LVS

Keepalived & IPVS

Page 80: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

OSI Layers

Page 81: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived Linux Process

Page 82: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalive(d) your Load-Balancers

Page 83: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived is simple in Linux

• Install: – apt-get install keepalived

• Configure:– vim /etc/keepalived/keepalived.conf

• Start Keepalived:– service keepalived start

• Stop Keepalived:– service keepalived stop

Page 84: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived Logs

• Read the logs: – tail /var/log/syslog

• How it looks:

Page 85: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Keepalived Configuration

Location:/etc/keepalived/keepalived.conf

Page 86: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

global_defs {}vrrp_script chk_service { # Requires keepalived-1.1.13 script "killall -0 keepalived" # cheaper than pidof interval 2 # check every 2 seconds weight 2 # add 2 points of priority if OK}vrrp_instance VI_1 { state master interface eth0 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type <PASS-TYPE> auth_pass <PASSWORD> } virtual_ipaddress { 192.168.108.10 dev eth0 label eth0:0 } track_script { chk_service }}

Page 87: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 88: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAPROXY

Page 89: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy: What is it?

• Realible, High Performance Load Balancer• Can Load-balance both TCP and HTTP• Can handle massive amounts of traffic• Can queue up requests for a server• Can be configured to send specific amounts of

traffic to an application:– Configure to never sends more than you can handle– Helpful for heavy apps

Page 90: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy: Who uses it?

• Who uses it? Internet Giants:– Twitter– Instagram– Reddit– Tumblr– Airbnb– Farmville– Imgur– Github– TaoBao: Largest Picture Content Distribution Network in the World – <insert censored site> uses it

Page 91: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy:

• How do we use it?– HTTP Load-Balancing– TCP Load-Balancing– Health Checks– Statistics

Page 92: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

YOU TOO CAN SCALE APPS

Page 93: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy is a breeze to setup:

• Install: – add-apt-repository ppa:vbernat/haproxy-1.5– apt-get install haproxy

• Configure:– vim /etc/haproxy/haproxy.cfg

Page 94: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy, simple administration:

• Start:– service haproxy start

• Stop:– service haproxy stop

• Restart:– service haproxy restart

Page 95: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy is simple & powerful:

Page 96: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 97: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy s Keepalived

Page 98: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 99: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

HAProxy is simple & powerful:

Page 100: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

TLS

Page 101: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Transport Layer Security

• TLS is a protocol that ensures privacy between communicating applications and their users

• When a server and client communicate, TLS aims to ensure that no third party may eavesdrop or tamper with any message.

• TLS is the successor to the Secure Sockets Layer (SSL).

Page 102: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Transport Layer Security

• SSLv1, SSLv2, SSLv3 and TLSv1 are all vulnerable

• Weakest protocol supported by the system is used for attacks– POODLE– HEARTBLEED

Page 103: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Transport Layer Security

• Check your servers for insecure cyphers and protocols:– https://www.ssllabs.com

• Man in the middle attacks can decrypt HTTPS data

Page 104: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Transport Layer Security

Page 105: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSL Termination

Page 106: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSL Termination (HAProxy)

Page 107: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSL Termination

Page 108: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

KEY AUTHENTICATION (SSH)

Page 109: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Secure Shell

• SSH is a cryptographic (encrypted) network protocol • Used for initiating text-based shell sessions • Used for administering remote machines in a secure

way– Network Switches– Servers

• Can authenticate using:– Username / Password (less secure)– SSH Keys (more secure)

Page 110: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Secure Shell

• /home/acolon/.ssh/– Same as: ~/.ssh/

• Contains:– Cryptographic keys– Authorized Keys and machines

Page 111: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSH Hidden Folder

• cd• mkdir ~/.ssh • chmod 700 • cd ~/.ssh/• ssh-keygen -t rsa

Page 112: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSH: Generate your Keys

Page 113: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSH: Generate your Keys

• Default is 2048 bit key• Use: ssh-keygen -t rsa -b 4096

Page 114: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

SSH: Transfer your Keys

• One way:– ssh-copy-id <username>@<host>– Example: ssh-copy-id [email protected]

• Or:– Copy your public key to the server– cp authorized_keys authorized_keys_Backup– cat id_rsa.pub >> authorized_keys

Page 115: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Secure Shell

Page 116: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Secure Shell

Page 117: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Why SSH Authentication?

• Far more Secure• Difficult to crack• Less prone to Brute Force attacks• Multiple users can authenticate

Page 118: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Week 3

Knowledge TransferNew PR.gov Infrastructure

Good Standing Certificate Service

Page 119: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

What’s the Plan?

• Last week Q&A• Overview of Knowledge Transfer Plan Week 3• Knowledge Transfer Talk Topics: Week 3

Page 120: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Q&A - Last week we saw:

Infrastructure Services:• Keepalived (high-availability with VRRP in Linux)• HaProxy (Load-Balancing in Linux)

– Introduction– HTTP Load-Balancing– TCP Load-Balancing– Health Checks

• Transport Layer Security (TLS) & SSL vulnerabilities• Passwordless Authentication – SSH Key Authentication

Page 121: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Overview of technologies in Operations:

Infrastructure Services:• Advanced Key Value Store: Redis• PostFix• Bind9

Page 122: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Databases

• There isn’t a “one-size fits all” • Choosing the right tech, hinges on use case• If your data doesn’t change and has moderate

manageable growth: SQL not dead for you• High throughput and growth, efficient scaling,

rapid data change: NoSQL

Page 123: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

RDBMS• Scalability:

– Scability is vertical– More data usually means bigger servers– Scaling across multiple servers is possible but time-consuming

• Fixed Schema– Must be decided and locked before data entry

• ACID compliance• Stored in Relational Model

– Rows: contain all information about specific entity– Columns: contain all the seperate data points about entity.

Page 124: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Choose the Right Tool for the Job

Page 125: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Polyglot Persistence

“Use the right tool for what you’re trying to accomplish”

CAP:Our project uses both SQL and NoSQL– PR.gov successfully implements NoSQL (Redis)– RCI uses both SQL and NoSQL (MSSQL, MongoDB)

Page 126: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 127: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

What is NoSQL?

• An alternate way of thinking about databases• NoSQL = “Not Only SQL” • Not a Relational Database• Data not modeled in terms of tabular relations• Some NoSQL databases are ACID compliant,

but some sacrifice compliancy for performance and scalability

Page 128: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

How many types of NoSQL?

There are plenty of NoSQL flavours:• Key-Value Stores• Document databases• Graph Databases• Wide Column Databases

Page 129: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

NoSQL Adoption

• Size Matters:– When working with large datasets, consistently scaling is

easier to achieve with many NoSQL family• Speed:– NoSQL is usually faster and sometimes extremely

speedier in writes– Reads can also be very fast depending on the NoSQL DB

used and data being queried• NoSQL has seen rapid adoption in web-technologies

Page 130: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Why NoSQL?

Page 131: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Data in NoSQL

• Key-Value Stores– Associative Array of key-value Pairs

• Document databases– Stored as collection of document, structure can vary

• Graph Databases– Data is stored in nodes, properties and lines

• Wide Column Databases– Data is stored in column families, rows can have

different columns

Page 132: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 133: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Popular NoSQL Examples

• Key-Value Stores– Redis

• Document databases– MongoDB

• Graph Databases– Neo4J

• Wide Column Databases– Cassandra & Hbase

Page 134: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Examples of NoSQL

Page 135: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

NoSQL Adoption

Page 136: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

IN-MEMORY DATABASEURL: Redis.io (Remote Dictionary Server)

Page 137: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Introduction to Redis• Most important feature: high-performance• Advanced Key-Value Store• Often referred to as a Data Structure Server• Open Source (BSD license)• Built-in replication • Multiple Persistence Options• Read and Write speeds obsessively

documented

Page 138: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: high-performance• In-memory database• Small code-base (20k lines in C)• Connection via TCP or Unix Socket• No nested data structures• Persistence via Snapshotting and/or Journaling• Master/Slave chain database replication• Sentinel Server Monitoring – real clustering

now in beta

Page 139: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Uses Cases• Caching• Statistics collection (downloads, hits, time

benchmarks)• Log buffers• Tasks Queues• Share state between processes • Inter-proccess communication in a distributed

network• Built-in Publish Subscribe

Page 140: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Who uses it?• Twitter• Instagram• Pinterest• Snapchat• StackOverflow• Airbnb• Tumblr• Flickr• Craiglist• Hulu• Imgur

Page 141: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Why we love it!• Automatic Key Expiration • Great for both caching and storage• Scales for millions of requests • Used for fast, self-expiring sessions on Web App• Used for fast, self-expiring transactions on GMQ • Powerful Libraries available for EventMachine

(Reactor Pattern) used by our GMQ API for Redis• Redis used by Github’s Resque for asynchronous

workers

Page 142: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Cap Redis• Used primarily as:– Web Session Storage – Transaction Storage– Workers Coordination – Statistics

Page 143: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Data Structure• Often referred to as a Data Structure Server– Can contain Strings– Hashes– Lists– Sets– Sorted sets– Bitmaps

Page 144: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Data Types

Page 145: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Master the Data Types• Redis can be used as Key Value storage• But to get the most out of it, think of it as a tool set• When designing for efficiency, think how to best model

your data using the myriad of available data types• Think of how you want to store your data, including the

key

Page 146: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: InstallationQuick install:

Detailed configuration:http://redis.io/topics/quickstart

Page 147: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Starting and Shutting down

Start your server:

Shutdown your server:

Page 148: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Connect to Redis

• redis-cli allows you to connect to a redis server

• It accepts arguments as commands, such as:

Page 149: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Connect to Redis

Page 150: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Connect to Redis

Page 151: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Testing Redis

Page 152: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Testing Redis

Page 153: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Hashes in Redis

Page 154: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Think of hashes as:

• “users:1” => { :name => “andres”, :rank => 1 }

Page 155: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Testing Redis

Page 156: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Connect Ruby to Redis

Page 157: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Connect Ruby to Redis

Page 158: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 159: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Pub/Sub

Page 160: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Pub/Sub

Page 161: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Persistence• In-memory

– No storage on disks. Useful for caches• RDB

– Favors performance over persistence– Very compact single-file representation– Perfect for Backups (backup daily, keep snapshots for months)– Very good for disaster recovery (compact, easily transferable)– RDB maximizes performance since all the parent process needs to do in order to persist is forking a

child that will do all the rest. The parent instance will never perform disk I/O or alike.– Can save every X seconds or if more than Y number of transactions have been changed

• AOF– Favors persistence over performance– Much more durable than RDB– An append-only log, there are no seeks nor corruption problems if power failure– If log ends with half-written command (disk-failure, etc), redis-check-aof tool fixes it easily– Much bigger than RDB– More aggressive storage, as it favors persistence

Page 162: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Redis: Replication

Page 163: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

EMAIL SERVERMail relay

Page 164: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Email

• One of the most popular internet services to date

• Facilitates communication• MTA – mail transfer agents, move mail from

one mail system to another• MDA – mail delivery agents, move mail from

one system to the user’s mailbox

Page 165: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix• Free open source mail transfer agent (MTA)• Handles routing and delivery of email• Solid Email Server for Linux• The default MTA for a number linux

distributions including Ubuntu• Very useful for SMTP Relay• Quick setup, very reliable

Page 166: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix Queues• Incoming Queue:– Receives mail from other hosts– As long as emails are arriving and it hasn’t been

processed, it is kept in this queue• Active queue:– The queue that actually deliver messages– It has a limited size and messages are accepted if

there is space for them. Other queues must wait for the active queue to be ready to accept items.

Page 167: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix Queues• Deferred queue:– Email that cannot be delivered– Prevents the system from continously trying to deliver

email– Keeps the active queue short, by storing failed emails,

and thus newer messages get priority– Enhances stability– If MTA cannot reach a domain, emails are stored here– Retry is scheduled with an increasing waiting time. – After wait, the item is put on the active queue.

Page 168: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

CAP and email relays

Page 169: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix: how we use it

• GMQ provides a REST interface for mailing• GMQ workers queue jobs in relay server• Postfix mail server is not exposed to the

internet• Traffic is only outbound, not inbound

Page 170: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix: Installation

• sudo apt-get install postfix• Select “Internet Site”• Enter name of your domain• Additional configuration:– Edit: /etc/postfix/main.cf

• Sender Policy Framework (SPF) record is important for the domain you wish to relay

Page 171: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix: Installation

• Postfix start – starts the server• Postfix stop – stop the server• Postfix reload – reloads configuration without

downtime

Page 172: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Postfix: Important commands:

• check queue size:– mailq

• Check current queue:– postqueue –q

• Flush the queue (force resend):– postqueue –f

• Show number of emails being sent to each domain:– qshape active

• Same as above but for deferred queue– qshape deferred

Page 173: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

BIND9DNS

Page 174: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

DNS

• Allows not to hard-code IPs in our network• Possible to associate multiple names to the

same machine to update the different available services

• Makes our infrastructure more resilient to future changes

Page 175: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Bind9

• Free Open Source DNS Server• Massively popular in the linux community• Resilient and easy to install and configure• Allows for master and slaves DNS• Allows for zone transfers

Page 176: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Commands

• Install:– sudo apt-get install bind9

• Start:– /etc/init.d/bind9 start

• Restart:– /etc/init.d/bind9 restart

• Stop– /etc/init.d/bind9 stop

Page 177: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Configure

• Files:– /etc/bind/

• Local configuration:– /etc/bind/named.conf.local

Page 178: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Configure

• Files:– /etc/bind/

• Local configuration:– /etc/bind/named.conf.local

Page 179: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Configure

• Zones:– /etc/bind/zones/

Page 180: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Configure

• Zones:– /etc/bind/zones/

Page 181: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Next week (4) – Save the Date!

Basic Core Application Technologies:• Ruby Programming Language• Gems• Environment variables (DotEnv)• Rake• Bundler• Internationalization (i18n)

Page 182: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Week 4

Knowledge TransferNew PR.gov Infrastructure

Good Standing Certificate Service

Page 183: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

What’s the Plan?

• Last week Q&A• Overview of Knowledge Transfer Plan Week 4• Knowledge Transfer Talk Topics: Week

Page 184: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Q&A - Last week we saw:

Infrastructure Services:• Advanced Key Value Store: Redis• PostFix• Bind9

Page 185: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basic Core Application Technologies:

Infrastructure Services:• Ruby• Gems• DotEnv• Rake• Bundler• Internationalization (i18n)

Page 186: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 187: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

RUBY

Page 188: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Topics

• Some thoughts on Programming Languages• Ruby History• Who uses Ruby• Ruby Basics• Learn Ruby by Example

Page 189: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

The Principles of Languages

• Thinking is Important for Programmers, we can only code what we can think

• But how do we think?– In words of specific languages– We grasp the world by language and express

ourselves with them– Languages are not only tools to communicate but

also tools to Think

Page 190: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Programmer’s Thoughts

• Natural languages are:– too ambiguos,– too verbose– too indirect

• In code, written down thoughts become programs

Page 191: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ever been frustrated with Programming?

Page 192: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 193: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Not all languages are created equal

Page 194: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Everyone can become frustrated with a specific Language. Try a new one.

Page 195: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 196: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About Ruby

Ruby is a dynamic, object-oriented, general-purpose programming language.

Page 197: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About Ruby

Ruby is a:• dynamic, • object-oriented, • general-purpose programming

language

Page 198: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Dynamic Languages

High-level programming languages which at runtime, execute many common programming behaviors that static programming languages perform during compilation.

Page 199: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Object Oriented Programming (OOP)

A programming paradigm based on the concept of "objects”, which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.

Page 200: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

General Purpose Language

In computer software a general-purpose programming language is a programming language designed to be used for writing software in a wide variety of application domains.

Page 201: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About Ruby: History

• Relatively young, 1995• From Japan• Designed to be Natural• Grew hugely in popularity with the Rails

Framework (Ruby on Rails)

Page 202: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About Ruby

• Free:– Developed as open source with a very open

license– Freedom to learn from the source– Freedom to extend and modify

Page 203: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About Ruby

• Ruby is strong in scripting as Perl– Built in regular expressions– Almost all equivalent functionality

• Can access all system calls on the Operating System via a standard library– Ruby/DL (Dynamic Loading)– Explicit libraries: syscall, Win32API

• Useful for scripting, but not limited to it

Page 204: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

About Ruby

• Ruby’s OOP Features:– Object• Everything is an object

– Class• Every class is an object

– Methods• Every procedure is a method;

Page 205: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

OK! LET’S COMPARE“Hello World!”

Page 206: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hello World: LotusScript

%INCLUDE "symphonylsx.lss"

Dim application As SymphonyApplication Dim documents As SymphonyDocuments Dim document As SymphonyDocument Dim range As SymphonyTextRange Set application = New SymphonyApplication Set documents = application.Documents Set document = documents.AddDocument("",True,True) Set range = document.content.End Call range.InsertBefore("Hello World")

Page 207: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hello World: C#

Page 208: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hello World: Objective-C

Page 209: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hello World: Visual Basic

Page 210: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hello World: Java

Page 211: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

In Ruby

puts “Hello, World!”

Page 212: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 213: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ruby is focused on programmer productivity

over machine optimization

Page 214: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 215: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 216: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ruby Uses

• Simulations• 3D Modeling• Business• Robotics• Networking• Game Development• System Administration• Web Applications• Security

Page 217: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Who is Using it?

• NASA (Langely Research Center)• Google (Sketchup) • Lucent (3G wireless telephony product)• Level 3 Communications (central data collection for

over 1,700 global servers)• 37Signals (Basecamp)• Twitter• AT&T (YellowPages.com) • StateFarm (R&D Center)

Page 218: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ruby Features

• Cross Platform • Object Oriented• Powerful string operations• Variables are not typed• Regular Expressions

Page 219: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ruby Features

• Class Inheritance• Garbage Collection• Threads• Iterators and Closures• Exception Handling• Operator Overloading• Introspection, Reflection, Meta Programming

Page 220: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Variables

key = value

Page 221: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Variables

agua = 0> 0presupuesto = 0> 0

Page 222: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Types of Variables

Capitalized variable names are known as constants. Cannot be chaned:CONSTANT = “light speed”

Page 223: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Types of Variables

•Constant variables• Local variables•Global variables•Class variables• Instance variables

Page 224: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Constant Variables

Capitalized variable names are known as constants, and their value should only be assigned once.

Page 225: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Constant Variables

Page 226: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Types of Variables

• Constant variables– Cannot be changed.

• Local variables– Local to a specific scope. Such as a method.

• Global variables– Accessible through the entire progarm

• Class variables– Accessible to the class.

• Instance variables– Specific to each instance of a class

Page 227: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Comment Code

# this is a commentkey = value

Page 228: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basic Comparison Operators

key == key2 # (equal)key != key2 # (not equal)key > key2 # (bigger than)Key < key2 # (smaller than)key >= key2 #(bigger or equal)key <= key2 # (less or equal)

Page 229: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basic Comparison Operators

Page 230: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Other Comparison Operators

Page 231: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Comparison Operation

prespuesto == agua> true

Page 232: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basic: Assignment Operations

Page 233: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basic: Assignment Operations

Page 234: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Examples: You can store the output

agua + 1> 1agua> 0 agua = agua + 1> 1agua> 1agua += 1> 2

Page 235: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Logical Operators

Page 236: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Logical Operators

Page 237: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Conditionals

if(condition) …end

Page 238: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Conditionals

if(condition and !condition2) …end

Page 239: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Conditionals

if(condition) …else … end

Page 240: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Conditionals

if(condition) …else … end

Page 241: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Conditionals

if(condition) …elsif (condition2 == value) …else … end

Page 242: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Conditionals

Page 243: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Methods

def method_name …

end

Page 244: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Methods

def say_hiputs “Hi”

endsay_hi> “Hi”

Page 245: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Methods and arguments

def method_name(argument)…

end

Page 246: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basics: Methods and arguments

def method_name(argument)…

end

Page 247: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Methods and arguments

Page 248: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Methods and arguments

Page 249: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Basic: Call methods from Methods

Page 250: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Putting it all together

Page 251: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Example: Parenthesis are optional

Page 252: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Classes

Page 253: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Instantiating a Class

Page 254: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Adding instance variable for Class

Page 255: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Adding instance variable for Class

Page 256: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Adding methods to our Class

Page 257: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Adding methods to our Class

Page 258: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hands-on Experience

• Now we’re going to have a hands-on experience with Ruby

• Let’s see some examples • Let’s modify them real-time based on Q&A • Let’s catch up on some basic Git

Page 259: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Learn Ruby by Example - Follow me to github:https://github.com/mindware/cap_ruby_training.git

Page 260: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Let’s Learn by Example

• Loops– Basics– Hashes– Arrays

• Classes– Instances– Methods– Getters and Setters– Inheritance– Namespaces

Page 261: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Let’s Learn by Example

• Gems• DotEnv and Environment Variables• Rake• Bundler• Internationalization

Page 262: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

…Done! What we did:

• We practiced Git for version control• We learned some ruby basics • We saw some cool ruby examples• Now let’s learn about Ruby Gems

Page 263: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Hashes

Page 264: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

GEMS

Page 265: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

GEMS LABS DEMO

Page 266: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 267: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

DOTENV

Page 268: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Installating dotenv system-wide

gem install dotenv

Page 269: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Bundling dotenv

Simply add to your Gemfile:

gem ‘dotenv’

bundle install

Page 270: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Create your Secret file

File name: .env Content:DB_PASSWORD=my secretDB_USER=my user

Page 271: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Accesing the value

require ‘dotenv’Dotenv.load

puts ENV[“DB_PASSWORD”] # outputs: ‘my secret’

Page 272: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

DOTENV EXAMPLETime for a Demo

Page 273: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 274: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Rack is the foundation for all modern Ruby Web Frameworks

Page 275: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Rack provides a common interface between server and Applications.

Page 276: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

Page 277: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Rack allows you to write once and run everywhere:• Puma• Goliath• Thin• Webrick

Page 278: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 279: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Built for:• Speed• Parallelism• Runs Rack Apps only

Page 280: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Global Installation:gem install puma

Page 281: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Bundler installationgem ‘puma’

Then:bundle install

Run the server: bundle exec puma

Page 282: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Puma powers CAP Web Applications

Page 283: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Command:

puma -t 0:8 -w 4 -p 3000 -e production --preload config.ru

Page 284: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 285: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Detailed Demo

• Let’s see some demos and practice:– EventMachine– Goliath– Grape– Sinatra– Padrino– Redis-Rb– Hi-Redis– EM::Synchrony

• Q&A

Page 286: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Detailed Demo

• Let’s see some demos and practice:– EventMachine– Goliath– Grape– Sinatra– Padrino– Redis-Rb– Hi-Redis– EM::Synchrony

• Q&A

Page 287: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Now let’s see how we used these:

• Let’s review our Github Source Code for:– CAP Web App– GMQ CAP API– GMQ Workers

• Head over to:– https://github.com/commonwealth-of-puerto-rico

• Q&A

Page 288: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Topics

• CAP Project Overview• Q&A

Page 289: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Project Overview

• What was wrong• What we did to fix it• What we achieved• Moving forward

Page 290: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

PR.gov Infrastructure Topics

• Security Philosophy• Networks Segments• Virtual Router Redundancy Protocol• Documentation

Page 291: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

PROJECT OVERVIEW(in Spanish)

Page 292: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Certificado de Antecedentes

Penales y Nuevo App de

PRGOV

Page 293: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 294: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

En 36 dias:

64,366 solicitudes recibidas

98%

2%

PR.govCompletadas Pendientes

Page 295: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

En Menos de 36 dias:

Page 296: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

En Menos de 30 dias:

Page 297: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

LOS RETOS

Page 298: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

• En la prensa se publicaron algunos de los problemas, pero no todos. Tip of the Iceberg.

• El certificado anterior incorporaba información que no habia sido validada con otras agencias.

• Muchos patronos utilizaban información en el certificado que la Policia no habia validado correctamente.

Page 299: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

En el antiguo sistema: si se entraba un seguro social inventado, con la información (falsa) de Homero Simpson, la Policia le emitia un certificado sin validar la identidad.

Page 300: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 301: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

En las profundidades….• Habia personas cometiendo

fraude con estos certificados;• Sistema se apagaba 8 horas para

hacer backup;• Solicitudes no se reintentaban si

ocurrían un fallos básicos en el

Page 302: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

• En los intentos de fraude, el Registro Demográfico de la Policía almacenaba información incorrecta y luego no emitía certificado verdadero dueño del seguro social;

• No habia forma de consultar datos de delitos menos graves de la Policia, por lo que los certificados no cumplian con la ley.

Page 303: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Mas abajo: • Los datos se encontraba en 4 bancos de datos

distintos, que no se hablaban entre si. • RCC, el sistema de Justicia que alimentaba el

banco de datos principal de la Policia, seria decomisado en semanas.

• Policia no tenia forma de sincronizar los delitos Graves de forma automatizada y necesitaban ayuda

Page 304: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Y en el fondo…

Page 305: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Retos que enfrentamosAsí sincronizaban los datos

Tribunales y la Policía de Puerto Rico.

Page 306: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Retos que enfrentamos

Page 307: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Toda solicitud de certificado en línea requeria una validación manual. Un promedio de 2 meses de espera para recibir el certificado.

Page 308: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

- playbook.cio.gov

Page 309: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

- playbook.cio.gov

+ Understand what people need+ Use Data to Drive decisions

Page 310: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ciudadanía Móvil

77% Mobile First

Los celulares son el principalmedio de acceso al Internet

en Puerto Rico

Page 311: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Ciudadanía Móvil:

Page 312: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

- playbook.cio.gov

+ Bring in experienced teams

Page 313: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

OPEI

Page 314: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Estrategia

PR.Gov App - Gestor

Policia /Justicia /Tribunales – Registro Criminal

DTOP/NCIC - Identidad

Page 315: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

- playbook.cio.gov

+ Choose a modern Techology Stack

Page 316: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Technology Stack

Page 317: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

- playbook.cio.gov

+ Default to open

Page 318: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Código Disponible en Github

https://github.com/commonwealth-of-puerto-rico/prgov_cap_webapp/

Page 319: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

START

Ready!

Modulos para la Policia

Desarrollo de APIs y Micro Services (RCI) Equipo

Componentes Técnicos

Desarollo de Web App

Desarollo de SistemaDe Mensajeria Gubernamental PR.Gov

Personal Técnico, Agilidad en Contratación y Accesos

Page 320: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

ANTES…

Page 321: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

…Antes:

Page 322: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

…Antes:

Page 323: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

…Antes:

Page 324: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

…Antes:

Page 325: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

…Antes:• En fallas, las solicitudes no se reintentaban automaticamente• No se emitian certificados positivos• No se validaba la información de identidad previo a la emisión• Certificados emitidos en ventanilla no era posible invalidarlos

posteriormente una vez emitido, aún si contenian errores.• Certificado de PR.gov era aceptado por patronos, pero se imprimia en hoja

de papel regular. • Policia emitia en papel especial con un alto costo para la agencia. • La seguridad del papel no era funcional toda vez que si emitian

incorrectamente un certificado, no podian cancelarlo. • Certificado no expiraba.

Page 326: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

NUEVO SERVICIO

Page 327: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 328: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 329: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 330: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 331: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 332: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Validación de Identidad:

• Aceptamos con o sin acentos, mayuzcula o minuscula.

• La información de las agencias es la utilizada. • El sistema tiene inteligencia para detectar posibles

errores en los nombres e identificar apropiadamente.

• Si toda la validación es correcta, se emite certificado. • De requerir evaluación humana, se envia a analista

de la Policia

Page 333: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Certificados en su Email

Page 334: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Retos del Beta• Algunas personas tienen su información

incorrecta en DTOP y estamos colaborando interagencialmente en el particular

• Interesamos incorporar nuevos métodos de validación en PR.gov (licencias de otros países, y pasaporte)

Page 335: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Logros (Alpha)• Consolidamos cuatro sistemas de datos

criminales en uno, adoptando RCI• Validación identidad del ciudadano en DTOP• Integración del registro de ofensores sexuales • Integración de modulo para entrada de los

delitos menos grave de la Policía • Un mismo proceso de validación, para solicitudes

presenciales en las ventanillas de la Policía y en línea en PR.gov

• Funciona en celulares y tabletas• Sistema escalable y con $0 costos de

licenciamiento

Page 336: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Logros (Beta)• Se emiten certificados positivos por primera vez

por PR.Gov• Certificados que antes salían negativos, ahora

salen positivos correctamente. • Se valida la identidad del ciudadano previo a la

emisión.• Se incorporó más allá que la tecnología, un

análisis de los procesos operacionales de la Policía, para atender sus necesidades.

• Servicio en español e inglés

Page 337: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Logros del Prototipo (Beta)• Servicio en español e inglés• Por primera vez, personal que es sentenciado,

busca certificado el mismo día, y se le emite positivo.

Page 338: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Emails: dia antes del lanzamiento

Page 339: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Tráfico: día antes del lanzamiento

Sistema de Mensajería Gubernamental:Transacciones completadas: 893Visitas al GMQ: 14933

Page 340: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Tráfico Móvil

Page 341: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

- playbook.cio.gov

+ Address the whole experience, from start to finish.

Page 342: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

El Primer App de PR.gov

Disponible para:

Android y Iphone

Page 343: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

PRGOV App

Page 344: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Escanea códigos de forma Segura

Page 345: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Solicita tu Certificado

Page 346: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service
Page 347: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service

Resumen:

• Nuevo Certificado es más seguro y rápido.• Require un ID de DTOP• Se trámita rápido y de forma segura• Funciona en tu móvil, tabletas y PCs• Versión beta está disponible en:– http://servicios.pr.gov/cap

• App de solicitud y validación disponible para Android y Iphone (keyword: PRGOV)

Page 348: Building Modern Digital Services on Scalable Private Government Infrastructures using Open Source Technologies for Public Service