Backend Runtimes
Ruby on Rails Backend Integration
Resolve visitor purchasing power parity pricing server-side in Rails controllers, Sinatra apps, and background billing jobs with sub-10ms Anycast edge resolution.
Production Rails Service with In-Memory Caching
Create a standalone service object with persistent connection pooling and automatic cache management:
# app/services/parity_pricing_service.rb
require 'faraday'
class ParityPricingService
EDGE_API_URL = 'https://api.parityedge.app/v1/lookup'.freeze
PROJECT_ID = 'prj_live_YOUR_KEY'.freeze
def self.calculate(base_price, client_ip)
parity = fetch_parity(client_ip)
if parity && parity['eligible'] && parity['discountPercentage'].to_i > 0
discount_multiplier = (100.0 - parity['discountPercentage'].to_f) / 100.0
final_price = (base_price * discount_multiplier).round(2)
{ base_price: base_price, final_price: final_price, parity: parity }
else
{ base_price: base_price, final_price: base_price, parity: parity }
end
end
def self.fetch_parity(client_ip)
cache_key = "parity_edge:#{client_ip}"
Rails.cache.fetch(cache_key, expires_in: 10.minutes) do
conn = Faraday.new(url: EDGE_API_URL) do |f|
f.options.open_timeout = 0.5
f.options.timeout = 1.0
f.response :json
end
response = conn.get do |req|
req.params['projectId'] = PROJECT_ID
req.headers['x-forwarded-for'] = client_ip.to_s
end
response.success? ? response.body : nil
rescue Faraday::Error => e
Rails.logger.warn "[ParityEdge] Edge lookup timeout/error: #{e.message}"
nil
end
end
endRails Controller & View Helper Integration
# app/controllers/pricing_controller.rb
class PricingController < ApplicationController
def show
client_ip = request.remote_ip
@pricing = ParityPricingService.calculate(49.00, client_ip)
respond_to do |format|
format.html
format.json { render json: @pricing }
end
end
end
# app/helpers/pricing_helper.rb
module PricingHelper
def render_parity_banner(parity)
return unless parity && parity['eligible']
tag.div(class: 'p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 text-xs font-semibold') do
"Special #{parity['discountPercentage']}% discount automatically applied for visitors from #{parity['countryName']}!"
end
end
endProduction Architecture Highlights
Fail-Open Circuit Safety
Outbound timeouts default gracefully to standard baseline USD rates, ensuring your billing and checkout flows never crash.
Autonomous ASN Threat Inspection
The ParityEdge edge engine verifies Autonomous System Numbers (ASNs) against commercial hosting ranges, preventing automated geographic discount abuse.