Oracle Cloud Infrastructure (OCI)
Purpose
Manage Oracle Cloud Infrastructure resources: compute, networking, storage, IAM, OKE (Kubernetes), Autonomous Database, and cost governance.
Agent Protocol
Trigger
Exact user phrases: "oracle cloud", "oci", "oke", "oracle kubernetes", "autonomous database", "oci compute", "oci networking", "oci iam".
Input Context
Before activating, verify:
OCI region(s) and tenancy OCID.
Compartment structure.
Authentication method (API key, instance principal, resource principal).
Terraform or OCI CLI for provisioning.
Output Artifact
OCI resource configurations (Terraform or CLI) or architecture documentation.
Response Format
Terraform HCL or OCI CLI commands. No preamble.
Completion Criteria
Networking: VCN, subnets, security lists, NSGs, route tables, DRG.
Compute: instance shapes, images, boot volumes, cloud-init.
Storage: object storage buckets, block volumes, file systems.
IAM: compartments, groups, policies, dynamic groups.
OKE: cluster, node pools, kubeconfig, ingress controller.
Database: Autonomous Database or DB system.
Governance: budgets, alerts, cost tags.
Max Response Length
400 lines.
Quick Start
Create a compartment → set up VCN with subnets and security lists → provision compute instance (VM.Standard.E4.Flex) → configure IAM policies → deploy OKE cluster → set up object storage for backups. All via oci CLI or Terraform.
Decision Tree: OCI Compute Shapes
Shape Family
Use Case
vCPUs
Memory
Networking
VM.Standard.E4.Flex
General purpose, AMD EPYC
1-64
1-512 GB
Up to 32 Gbps
VM.Standard.A1.Flex
ARM Ampere, cost-effective
1-80
1-512 GB
Up to 32 Gbps
BM.Optimized3.36
Bare metal, HPC
36
512 GB
100 Gbps
VM.GPU.A10.1
ML inference, graphics
15
120 GB
4 Gbps
VM.DenseIO.E4.Flex
NVMe local SSD, databases
1-64
1-512 GB
Up to 32 Gbps
Core Workflow
Step 1: OCI Networking
# VCN with public and private subnets
resource "oci_core_vcn" "main" {
compartment_id = var.compartment_ocid
display_name = "vcn-main"
cidr_blocks = ["10.0.0.0/16"]
dns_label = "vcnmain"
}
resource "oci_core_subnet" "public" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.main.id
cidr_block = "10.0.1.0/24"
display_name = "subnet-public"
security_list_ids = [oci_core_security_list.public.id]
route_table_id = oci_core_route_table.public.id
dns_label = "public"
}
resource "oci_core_subnet" "private" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.main.id
cidr_block = "10.0.2.0/24"
display_name = "subnet-private"
security_list_ids = [oci_core_security_list.private.id]
route_table_id = oci_core_route_table.private.id
dns_label = "private"
}
# Internet Gateway for public subnet
resource "oci_core_internet_gateway" "ig" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.main.id
display_name = "ig-main"
}
# NAT Gateway for private subnet outbound
resource "oci_core_nat_gateway" "nat" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.main.id
display_name = "nat-main"
}
Step 2: Security Lists and NSGs
# Security List (stateless, applies to whole subnet)
resource "oci_core_security_list" "public" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.main.id
display_name = "sl-public"
egress_security_rules {
destination = "0.0.0.0/0"
protocol = "6"
}
ingress_security_rules {
source = "0.0.0.0/0"
protocol = "6"
tcp_options {
min = 80
max = 80
}
}
ingress_security_rules {
source = "0.0.0.0/0"
protocol = "6"
tcp_options {
min = 443
max = 443
}
}
}
# Network Security Group (stateful, applies to individual instances)
resource "oci_core_network_security_group" "web" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_vcn.main.id
display_name = "nsg-web"
}
resource "oci_core_network_security_group_security_rule" "web_http" {
network_security_group_id = oci_core_network_security_group.web.id
direction = "INGRESS"
protocol = "6"
source = "0.0.0.0/0"
source_type = "CIDR_BLOCK"
tcp_options {
destination_port_range {
min = 80
max = 80
}
}
}
Step 3: Compute Instance
resource "oci_core_instance" "app" {
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
compartment_id = var.compartment_ocid
shape = "VM.Standard.E4.Flex"
shape_config {
ocpus = 4
memory_in_gbs = 32
}
display_name = "app-server"
source_details {
source_type = "image"
source_id = data.oci_core_images.ol8.images[0].id
}
create_vnic_details {
subnet_id = oci_core_subnet.private.id
assign_public_ip = false
nsg_ids = [oci_core_network_security_group.web.id]
}
metadata = {
ssh_authorized_keys = file(var.ssh_public_key_path)
user_data = base64encode(file("${path.module}/cloud-init.yaml"))
}
}
Step 4: OCI IAM
# Compartments
resource "oci_identity_compartment" "team" {
compartment_id = var.root_compartment_ocid
description = "Team workload compartment"
name = "team-compartment"
}
# Groups and Policies
resource "oci_identity_group" "ops" {
compartment_id = var.root_compartment_ocid
name = "DevOpsTeam"
description = "DevOps engineering team"
}
resource "oci_identity_policy" "ops_policy" {
compartment_id = var.root_compartment_ocid
name = "devops-policy"
description = "Policy for DevOps team"
statements = [
"Allow group DevOpsTeam to manage all-resources in compartment team-compartment",
"Allow group DevOpsTeam to read audit-events in tenancy",
"Allow group DevOpsTeam to use tag-namespaces in tenancy"
]
}
# Dynamic Group for compute instances
resource "oci_identity_dynamic_group" "compute" {
compartment_id = var.root_compartment_ocid
name = "ComputeInstances"
description = "All compute instances in prod"
matching_rule = "ALL {instance.compartment.id = '${oci_identity_compartment.team.id}'}"
}
Step 5: OKE (Oracle Kubernetes Engine)
resource "oci_containerengine_cluster" "oke" {
compartment_id = var.compartment_ocid
kubernetes_version = "v1.28.2"
name = "oke-prod"
vcn_id = oci_core_vcn.main.id
options {
service_lb_subnet_ids = [oci_core_subnet.public.id]
add_ons {
is_kubernetes_dashboard_enabled = false
is_tiller_enabled = false
}
admission_controller_options {
is_pod_security_policy_enabled = false
}
}
}
resource "oci_containerengine_node_pool" "pool" {
cluster_id = oci_containerengine_cluster.oke.id
compartment_id = var.compartment_ocid
kubernetes_version = "v1.28.2"
name = "pool-general"
node_shape = "VM.Standard.E4.Flex"
node_shape_config {
ocpus = 4
memory_in_gbs = 32
}
node_source_details {
source_type = "image"
image_id = data.oci_core_images.oke.images[0].id
}
subnet_ids = [oci_core_subnet.private.id]
quantity_per_subnet = 3
ssh_public_key = file(var.ssh_public_key_path)
initial_node_labels {
key = "pool"
value = "general"
}
}
Step 6: Autonomous Database
resource "oci_database_autonomous_database" "adb" {
compartment_id = var.compartment_ocid
db_name = "mydb"
display_name = "my-autonomous-db"
db_workload = "OLTP"
is_free_tier = false
db_version = "19c"
admin_password = var.db_admin_password
cpu_core_count = 4
data_storage_size_in_tbs = 1
whitelisted_ips = ["10.0.0.0/16"]
license_model = "BRING_YOUR_OWN_LICENSE"
# Enable auto-scaling
is_auto_scaling_enabled = true
# Database backups
is_backup_retention_enabled = true
backup_retention_period_in_days = 7
}
Step 7: Object Storage
resource "oci_objectstorage_bucket" "backup" {
compartment_id = var.compartment_ocid
name = "app-backups"
namespace = data.oci_objectstorage_namespace.ns.namespace
access_type = "NoPublicAccess"
storage_tier = "Standard"
object_events_enabled = true
# Lifecycle rules
retention_rules {
display_name = "7-year-retention"
duration {
time_amount = 7
time_unit = "YEARS"
}
}
}
resource "oci_objectstorage_bucket" "cold_storage" {
compartment_id = var.compartment_ocid
name = "archived-logs"
namespace = data.oci_objectstorage_namespace.ns.namespace
access_type = "NoPublicAccess"
storage_tier = "Archive"
auto_tiering = "INFREQUENT_ACCESS"
}
Step 8: FastConnect (Dedicated Private Connectivity)
resource "oci_core_fast_connect_provider_service" "provider" {
provider_service_name = "Megaport"
}
resource "oci_core_virtual_circuit" "fc_primary" {
compartment_id = var.compartment_ocid
type = "PRIVATE"
display_name = "fastconnect-primary"
bandwidth = 1000 # 1 Gbps
customer_bgp_asn = 65550
provider_service_id = data.oci_core_fast_connect_provider_services.provider.fast_connect_provider_services[0].id
provider_service_key_name = "megaport-key-primary"
gateway_id = oci_core_drg.main.id
cross_connect_mappings {
customer_bgp_peering_ip = "10.200.0.1/30"
oracle_bgp_peering_ip = "10.200.0.2/30"
}
}
Step 9: Resource Manager (Terraform Automation)
resource "oci_resourcemanager_stack" "infra" {
compartment_id = var.compartment_ocid
display_name = "infrastructure-stack"
description = "Base infrastructure deployment"
config_source {
config_source_type = "GIT_CONFIG_SOURCE"
configuration_source_provider_id = oci_resourcemanager_configuration_source_provider.github.id
branch_name = "main"
}
}
resource "oci_resourcemanager_job" "apply" {
stack_id = oci_resourcemanager_stack.infra.id
job_operation_details {
operation = "APPLY"
apply_job_plan_resolution {
resolution_strategy = "ALWAYS_USE_LATEST_PLAN"
}
}
}
Step 10: Monitoring and Alerts
resource "oci_monitoring_alarm" "cpu_high" {
compartment_id = var.compartment_ocid
alarm_summary = "High CPU utilization"
display_name = "cpu-utilization-high"
metric_compartment_id = var.compartment_ocid
namespace = "oci_computeagent"
query = "CpuUtilization[1m].mean() > 90"
severity = "WARNING"
body = "CPU > 90% for >1 minute on {resource.display_name}"
destinations = [oci_ons_topic.alarms.id]
is_enabled = true
repeat_duration = "PT15M"
}
Rules
Every resource must belong to a compartment — no root compartment resources.
Use NSGs for instance-level security; use Security Lists for subnet defaults.
Preflex Flex shapes over fixed OCPU shapes for cost efficiency and flexibility.
Enable auto-scaling on Autonomous Database for unpredictable workloads.
Use instance principals for OKE node pools to access object storage without keys.
Tag all resources with a cost-tracking tag namespace (Environment, Project, Owner).
Set up budgets and alerts before deploying production workloads.
Use OCI Vault for secrets, API keys, and database passwords.
Prefer FastConnect over site-to-site VPN for production hybrid connectivity.
Enable OKE cluster audit logs and ship to OCI Logging.
Production Considerations
OCI regions are organized by realm (commercial, government, China). Choose the right realm.
Availability domains (AD) are isolated within a region — 3 ADs in commercial regions.
Fault domains are within an AD — spread instances across all fault domains.
Block volume performance scales with size — allocate >= 320 GB for max IOPS.
OKE control plane is Oracle-managed (free) but node pools are your responsibility.
Use reserved (prepaid) compute for steady-state workloads to save up to 60%.
OCI Budgets support consumption-based and forecast-based alerts.
Exadata Cloud Service is available for extremely large Oracle Database workloads.
OCI WAF (Web Application Firewall) supports rate limiting, bot management, and CAPTCHA.
OCI Bastion service provides SSH/RDP access to private instances without public IPs.
Anti-Patterns
Using root compartment for resources — impossible to apply fine-grained policies.
Using fixed OCPU shapes (VM.Standard2.x) instead of Flex — wasteful and inflexible.
No VCN flow logs — can't troubleshoot connectivity issues.
Direct internet access from private subnets without NAT gateway.
S3 API compatibility assumed for OCI Object Storage — use OCI SDK or CLI.
Using Security Lists exclusively without NSGs — broader blast radius.
No budget alerts — surprise bills from misconfigured or attacked resources.
Manually managing OKE node pools — let cluster autoscaler or node pool management handle it.
Over-provisioning block volumes for IOPS — use performance tiers instead.
Ignoring OCI announcements service — unplanned maintenance surprises.
References
references/oci-compute.md — OCI Compute and Shapes
references/oci-networking.md — VCN, Subnets, Security Lists, DRG
references/oci-storage.md — Object Storage, Block Volume, File Storage
references/oci-oke.md — OKE Cluster and Node Pool Management
references/oracle-cloud-advanced.md — Oracle Cloud Advanced Topics
references/oracle-cloud-fundamentals.md — Oracle Cloud Fundamentals
Handoff
devops-terraform for Terraform state and module patterns for OCI.
devops-kubernetes for workload deployment on OKE clusters.
devops-docker for containerizing applications for OKE.
devops-hybrid-cloud for connecting OCI with on-prem or other clouds.
devops-backup-dr for OCI-based backup and DR strategies.
devops-observability for OCI logging and monitoring integration.
Architecture Decision Trees
OCI IAM vs Federation
Decision
OCI Native IAM
Federated (SSO/OIDC)
User management
OCI console, manual
Central IdP (Okta, Azure AD)
MFA
OCI built-in MFA
IdP-managed MFA
Group sync
Manual or API
SCIM provisioning
Audit trail
OCI Audit logs
IdP audit + OCI Audit
Complexity
Lower (in-platform)
Higher (IdP setup + mapping)
Best for
Small teams, isolated OCI
Enterprise with SSO requirement
Compute Shapes: AMD vs ARM (Ampere)
Aspect
AMD (Standard)
ARM / Ampere A1
vCPU ratio
1:2 per core
1:1 per core
Price-performance
Baseline
20-40% better for scale-out
Software compat
Universal
Requires ARM64 builds
GPU support
Available
Not available
Best for
General workloads, legacy
Containerized, web, K8s nodes
Implementation Patterns
Terraform: OCI VCN with Public and Private Subnets
resource "oci_identity_compartment" "prod" {
name = "production"
description = "Production compartment"
}
resource "oci_core_vcn" "main" {
compartment_id = oci_identity_compartment.prod.id
display_name = "production-vcn"
cidr_block = "10.0.0.0/16"
dns_label = "prod"
defined_tags = {
"Operations.CostCenter" = "12345"
}
}
resource "oci_core_subnet" "public" {
compartment_id = oci_identity_compartment.prod.id
vcn_id = oci_core_vcn.main.id
cidr_block = "10.0.1.0/24"
display_name = "public-lb"
security_list_ids = [oci_core_security_list.lb.id]
route_table_id = oci_core_route_table.public.id
dhcp_options_id = oci_core_dhcp_options.main.id
dns_label = "public"
prohibit_public_ip_on_vnic = false
}
resource "oci_core_subnet" "private" {
compartment_id = oci_identity_compartment.prod.id
vcn_id = oci_core_vcn.main.id
cidr_block = "10.0.2.0/24"
display_name = "private-app"
security_list_ids = [oci_core_security_list.app.id]
route_table_id = oci_core_route_table.private.id
dhcp_options_id = oci_core_dhcp_options.main.id
dns_label = "private"
prohibit_public_ip_on_vnic = true
}
resource "oci_core_instance" "app" {
compartment_id = oci_identity_compartment.prod.id
display_name = "app-server-01"
shape = "VM.Standard.A1.Flex"
shape_config {
ocpus = 4
memory_in_gbs = 24
}
source_details {
source_type = "image"
source_id = var.ol8_image_id
}
create_vnic_details {
subnet_id = oci_core_subnet.private.id
assign_public_ip = false
}
metadata = {
ssh_authorized_keys = var.ssh_public_key
}
}
Bash: OCI CLI Automation for OKE
#!/usr/bin/env bash
oci_login() {
oci session authenticate --region us-ashburn-1
}
oke_kubeconfig() {
local cluster_id=$1
oci ce cluster create-kubeconfig \
--cluster-id "$cluster_id" \
--file "${HOME}/.kube/oke-config" \
--region us-ashburn-1 \
--token-version 2.0.0
export KUBECONFIG="${HOME}/.kube/oke-config"
}
list_compartments() {
oci iam compartment list \
--compartment-id-in-subtree true \
--all \
--query 'data[*].{Name:name, Id:id, State:"lifecycle-state"}' \
--output table
}
Production Considerations
Use compartments for resource isolation per team/environment with IAM policies at compartment level
Enable OCI Cloud Guard target on every compartment for threat detection and misconfiguration alerts
Configure Vault (KMS) for encryption keys — encrypt all block volumes, object storage, and databases
Deploy OKE clusters with --pod-cidr and --service-cidr that don't overlap with on-prem or VCN ranges
Use Flex shapes (VM.Standard.E5.Flex) for most workloads — better price-performance than fixed shapes
Set up budgets at compartment level with threshold alerts to Slack/email
Enable VCN Flow Logs for network traffic analysis and security investigation
Anti-Patterns
Using root compartment for all resources — prevents fine-grained IAM and cost tracking
Exposing database ports (1521, 3306) to 0.0.0.0/0 in security lists — always scope to app subnet
Skipping OCI Vulnerability Scanning Service — containers and OS images should be scanned weekly
Using burstable shapes (VM.Standard.E2.1.Micro) for production — they throttle CPU under load
Ignoring block volume backups — enable automatic backups with 7-day retention as minimum
Applying broad IAM policies at tenancy level — use compartment-level policies with conditions
Over-provisioning boot volumes (default 50 GB) — resize only when needed to avoid waste
Performance Optimization
Use DenseIO shapes for database and analytics workloads requiring high local NVMe performance
Enable FastConnect for dedicated, low-latency connectivity to OCI regions
Configure load balancer with session persistence and health checks for zero-downtime deployments
Use OCI Object Storage with standard tier for frequently accessed data, infrequent tier for logs
Tune OKE worker node shapes by workload: VM.Standard.E5.Flex for general, BM.Optimized3.36 for AI/ML
Enable autoscaling on OKE node pools with cluster autoscaler and spot instances for batch workloads
Use OCI Cache (Redis) for session state and query result caching instead of local instance storage
Security Considerations
Enable OCI Identity Domain with MFA for all console users — enforce password policies
Use resource principal (instance principals) for OKE and Compute VMs — never store API keys
Restrict object storage bucket access with pre-authenticated requests (PAR) and least-privilege policies
Rotate OCI API keys every 90 days and use API key versioning for key rotation without downtime
Enable Cloud Guard with detector recipes for storage, networking, and IAM misconfigurations
Use Vault (HSM) for master encryption keys and auto-rotate DEKs every 180 days
Audit IAM policy changes with OCI Audit logs and stream to OCI Object Storage for retention
Implementation Patterns
Observer Pattern for Event Handling
`
interface EventObserver {
onEvent(event: T): Promise;
}
class EventBus {
private observers: Set<EventObserver> = new Set();
subscribe(observer: EventObserver): void {
this.observers.add(observer);
}
unsubscribe(observer: EventObserver): void {
this.observers.delete(observer);
}
async emit(event: T): Promise {
const results = Array.from(this.observers).map(o => o.onEvent(event));
await Promise.allSettled(results);
}
}
`
Configuration-Driven Approach
config: defaults: timeout: 30s retryCount: 3 overrides: production: timeout: 60s retryCount: 5 development: timeout: 300s retryCount: 1
Production Considerations
Deployment Checklist
Monitoring and Alerting
Metric
Threshold
Severity
Action
Error rate
> 1% over 5min
Critical
Page on-call
p99 latency
> 2s over 5min
Warning
Investigate
Throughput drop
> 50% over 1min
Critical
Check upstream
Queue depth
> 1000 over 1min
Warning
Scale consumers
Disk usage
> 85%
Warning
Clean or expand
Memory usage
> 90% heap
Critical
Restart or scale
Anti-Patterns
Anti-Pattern
Symptom
Root Cause
Solution
Premature optimization
Complex code for no measured benefit
Guessing instead of profiling
Measure first, optimize based on data
Copy-paste reuse
Duplicate code across codebase
Lack of abstraction
Extract shared logic into libraries
Gold-plating
Features with no current requirement
Over-engineering
YAGNI — build what's needed now
Magical thinking
Assumptions without validation
Skipping error handling
Handle all failure modes explicitly
Performance Optimization
Caching Strategy
Cache hierarchy: L1 (in-memory local) → L2 (distributed Redis/Memcached) → L3 (CDN/Edge).
Cache invalidation: TTL-based (simple, stale), event-based (complex, fresh), write-through (consistent, higher write latency), write-behind (fast writes, eventual consistency).
Resource Pooling
Database connections: Pool of reusable connections (HikariCP, pgBouncer)
HTTP connections: Keep-alive + connection pooling for external calls
Thread pool: Bounded thread pools for async task execution
Profiling Methodology
Establish baseline with production traffic profile
Profile CPU with sampling profiler (pprof, perf, async-profiler)
Profile memory with heap dumps and allocation tracking
Profile I/O with strace/perf trace for syscall analysis
Profile latency with distributed tracing (OpenTelemetry)
Identify bottleneck, formulate hypothesis, implement fix
Re-profile to verify improvement, repeat
Security Considerations
Threat Modeling (STRIDE)
Spoofing: Identity validation, authentication
Tampering: Integrity checks, digital signatures
Repudiation: Audit logs, non-repudiation
Information disclosure: Encryption, access control
Denial of service: Rate limiting, resource quotas
Elevation of privilege: Principle of least privilege
Supply Chain Security
Dependency scanning: Snyk, Dependabot, Trivy
SBOM generation: CycloneDX or SPDX format
Signed commits: GPG or SSH commit signing
Artifact verification: Checksum validation, signature verification
Secrets Management
Secrets never in code — always in secrets manager (Vault, AWS Secrets Manager)
Rotation policy: Rotate database credentials every 90 days
Access audit: Log every secrets access, alert on anomalies
Encryption at rest and in transit for all secrets
Principle of least privilege: each service gets only its own secrets
Rules
Default-deny security posture — allow only explicitly required access.
All inputs validated, all outputs encoded, all errors handled.
Defend in depth — multiple layers of security controls.
Fail securely — errors default to safe behavior.
Log security-relevant events for audit and investigation.
Keep dependencies updated — automate vulnerability scanning.
Design for observability from day one, not as an afterthought.
Document all architectural decisions with rationale.
Review code for security, performance, and correctness before merging.
1 --- 2 name: oracle-cloud 3 description: Use this skill when the user says 'oracle cloud', 'oci', 'oracle cloud infrastructure', 'oracle database cloud', 'oci compute', 'oci networking', 'oci storage', 'oci identity', 'oci iam', 'oracle autonomous database', 'oci load balancer', 'oci dns', 'oci functions', 'oci container engine', 'oke', 'oracle kubernetes', 'oci terraform', 'oci resource manager', 'oracle cloud regions', 'oci fastconnect', 'oci vcn', 'oci security list', 'oci nsg', 'oci bastion', 'oci vault', 'oci waf', 'oci email delivery', 'oci object storage', 'oci block volume', 'oci file storage', 'oci budget', 'oci cost analysis', 'oci announcements', 'oci support'. Covers: Oracle Cloud Infrastructure (OCI) resources, networking, compute, storage, IAM, OKE (Kubernetes), Autonomous Database, and governance. 4 license: MIT 5 --- 6 7 # Oracle Cloud Infrastructure (OCI) 8 9 ## Purpose 10 Manage Oracle Cloud Infrastructure resources: compute, networking, storage, IAM, OKE (Kubernetes), Autonomous Database, and cost governance. 11 12 ## Agent Protocol 13 14 ### Trigger 15 Exact user phrases: "oracle cloud", "oci", "oke", "oracle kubernetes", "autonomous database", "oci compute", "oci networking", "oci iam". 16 17 ### Input Context 18 Before activating, verify: 19 - OCI region(s) and tenancy OCID. 20 - Compartment structure. 21 - Authentication method (API key, instance principal, resource principal). 22 - Terraform or OCI CLI for provisioning. 23 24 ### Output Artifact 25 OCI resource configurations (Terraform or CLI) or architecture documentation. 26 27 ### Response Format 28 Terraform HCL or OCI CLI commands. No preamble. 29 30 ### Completion Criteria 31 - [ ] Networking: VCN, subnets, security lists, NSGs, route tables, DRG. 32 - [ ] Compute: instance shapes, images, boot volumes, cloud-init. 33 - [ ] Storage: object storage buckets, block volumes, file systems. 34 - [ ] IAM: compartments, groups, policies, dynamic groups. 35 - [ ] OKE: cluster, node pools, kubeconfig, ingress controller. 36 - [ ] Database: Autonomous Database or DB system. 37 - [ ] Governance: budgets, alerts, cost tags. 38 39 ### Max Response Length 40 400 lines. 41 42 ## Quick Start 43 Create a compartment → set up VCN with subnets and security lists → provision compute instance (VM.Standard.E4.Flex) → configure IAM policies → deploy OKE cluster → set up object storage for backups. All via `oci` CLI or Terraform. 44 45 ## Decision Tree: OCI Compute Shapes 46 | Shape Family | Use Case | vCPUs | Memory | Networking | 47 |-------------|----------|-------|--------|------------| 48 | **VM.Standard.E4.Flex** | General purpose, AMD EPYC | 1-64 | 1-512 GB | Up to 32 Gbps | 49 | **VM.Standard.A1.Flex** | ARM Ampere, cost-effective | 1-80 | 1-512 GB | Up to 32 Gbps | 50 | **BM.Optimized3.36** | Bare metal, HPC | 36 | 512 GB | 100 Gbps | 51 | **VM.GPU.A10.1** | ML inference, graphics | 15 | 120 GB | 4 Gbps | 52 | **VM.DenseIO.E4.Flex** | NVMe local SSD, databases | 1-64 | 1-512 GB | Up to 32 Gbps | 53 54 ## Core Workflow 55 56 ### Step 1: OCI Networking 57 ```hcl 58 # VCN with public and private subnets 59 resource "oci_core_vcn" "main" { 60 compartment_id = var.compartment_ocid 61 display_name = "vcn-main" 62 cidr_blocks = ["10.0.0.0/16"] 63 dns_label = "vcnmain" 64 } 65 66 resource "oci_core_subnet" "public" { 67 compartment_id = var.compartment_ocid 68 vcn_id = oci_core_vcn.main.id 69 cidr_block = "10.0.1.0/24" 70 display_name = "subnet-public" 71 security_list_ids = [oci_core_security_list.public.id] 72 route_table_id = oci_core_route_table.public.id 73 dns_label = "public" 74 } 75 76 resource "oci_core_subnet" "private" { 77 compartment_id = var.compartment_ocid 78 vcn_id = oci_core_vcn.main.id 79 cidr_block = "10.0.2.0/24" 80 display_name = "subnet-private" 81 security_list_ids = [oci_core_security_list.private.id] 82 route_table_id = oci_core_route_table.private.id 83 dns_label = "private" 84 } 85 86 # Internet Gateway for public subnet 87 resource "oci_core_internet_gateway" "ig" { 88 compartment_id = var.compartment_ocid 89 vcn_id = oci_core_vcn.main.id 90 display_name = "ig-main" 91 } 92 93 # NAT Gateway for private subnet outbound 94 resource "oci_core_nat_gateway" "nat" { 95 compartment_id = var.compartment_ocid 96 vcn_id = oci_core_vcn.main.id 97 display_name = "nat-main" 98 } 99 ``` 100 101 ### Step 2: Security Lists and NSGs 102 ```hcl 103 # Security List (stateless, applies to whole subnet) 104 resource "oci_core_security_list" "public" { 105 compartment_id = var.compartment_ocid 106 vcn_id = oci_core_vcn.main.id 107 display_name = "sl-public" 108 109 egress_security_rules { 110 destination = "0.0.0.0/0" 111 protocol = "6" 112 } 113 114 ingress_security_rules { 115 source = "0.0.0.0/0" 116 protocol = "6" 117 tcp_options { 118 min = 80 119 max = 80 120 } 121 } 122 ingress_security_rules { 123 source = "0.0.0.0/0" 124 protocol = "6" 125 tcp_options { 126 min = 443 127 max = 443 128 } 129 } 130 } 131 132 # Network Security Group (stateful, applies to individual instances) 133 resource "oci_core_network_security_group" "web" { 134 compartment_id = var.compartment_ocid 135 vcn_id = oci_core_vcn.main.id 136 display_name = "nsg-web" 137 } 138 139 resource "oci_core_network_security_group_security_rule" "web_http" { 140 network_security_group_id = oci_core_network_security_group.web.id 141 direction = "INGRESS" 142 protocol = "6" 143 source = "0.0.0.0/0" 144 source_type = "CIDR_BLOCK" 145 tcp_options { 146 destination_port_range { 147 min = 80 148 max = 80 149 } 150 } 151 } 152 ``` 153 154 ### Step 3: Compute Instance 155 ```hcl 156 resource "oci_core_instance" "app" { 157 availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name 158 compartment_id = var.compartment_ocid 159 shape = "VM.Standard.E4.Flex" 160 shape_config { 161 ocpus = 4 162 memory_in_gbs = 32 163 } 164 display_name = "app-server" 165 166 source_details { 167 source_type = "image" 168 source_id = data.oci_core_images.ol8.images[0].id 169 } 170 171 create_vnic_details { 172 subnet_id = oci_core_subnet.private.id 173 assign_public_ip = false 174 nsg_ids = [oci_core_network_security_group.web.id] 175 } 176 177 metadata = { 178 ssh_authorized_keys = file(var.ssh_public_key_path) 179 user_data = base64encode(file("${path.module}/cloud-init.yaml")) 180 } 181 } 182 ``` 183 184 ### Step 4: OCI IAM 185 ```hcl 186 # Compartments 187 resource "oci_identity_compartment" "team" { 188 compartment_id = var.root_compartment_ocid 189 description = "Team workload compartment" 190 name = "team-compartment" 191 } 192 193 # Groups and Policies 194 resource "oci_identity_group" "ops" { 195 compartment_id = var.root_compartment_ocid 196 name = "DevOpsTeam" 197 description = "DevOps engineering team" 198 } 199 200 resource "oci_identity_policy" "ops_policy" { 201 compartment_id = var.root_compartment_ocid 202 name = "devops-policy" 203 description = "Policy for DevOps team" 204 statements = [ 205 "Allow group DevOpsTeam to manage all-resources in compartment team-compartment", 206 "Allow group DevOpsTeam to read audit-events in tenancy", 207 "Allow group DevOpsTeam to use tag-namespaces in tenancy" 208 ] 209 } 210 211 # Dynamic Group for compute instances 212 resource "oci_identity_dynamic_group" "compute" { 213 compartment_id = var.root_compartment_ocid 214 name = "ComputeInstances" 215 description = "All compute instances in prod" 216 matching_rule = "ALL {instance.compartment.id = '${oci_identity_compartment.team.id}'}" 217 } 218 ``` 219 220 ### Step 5: OKE (Oracle Kubernetes Engine) 221 ```hcl 222 resource "oci_containerengine_cluster" "oke" { 223 compartment_id = var.compartment_ocid 224 kubernetes_version = "v1.28.2" 225 name = "oke-prod" 226 vcn_id = oci_core_vcn.main.id 227 228 options { 229 service_lb_subnet_ids = [oci_core_subnet.public.id] 230 231 add_ons { 232 is_kubernetes_dashboard_enabled = false 233 is_tiller_enabled = false 234 } 235 236 admission_controller_options { 237 is_pod_security_policy_enabled = false 238 } 239 } 240 } 241 242 resource "oci_containerengine_node_pool" "pool" { 243 cluster_id = oci_containerengine_cluster.oke.id 244 compartment_id = var.compartment_ocid 245 kubernetes_version = "v1.28.2" 246 name = "pool-general" 247 node_shape = "VM.Standard.E4.Flex" 248 node_shape_config { 249 ocpus = 4 250 memory_in_gbs = 32 251 } 252 node_source_details { 253 source_type = "image" 254 image_id = data.oci_core_images.oke.images[0].id 255 } 256 subnet_ids = [oci_core_subnet.private.id] 257 quantity_per_subnet = 3 258 ssh_public_key = file(var.ssh_public_key_path) 259 260 initial_node_labels { 261 key = "pool" 262 value = "general" 263 } 264 } 265 ``` 266 267 ### Step 6: Autonomous Database 268 ```hcl 269 resource "oci_database_autonomous_database" "adb" { 270 compartment_id = var.compartment_ocid 271 db_name = "mydb" 272 display_name = "my-autonomous-db" 273 db_workload = "OLTP" 274 is_free_tier = false 275 db_version = "19c" 276 277 admin_password = var.db_admin_password 278 cpu_core_count = 4 279 data_storage_size_in_tbs = 1 280 281 whitelisted_ips = ["10.0.0.0/16"] 282 license_model = "BRING_YOUR_OWN_LICENSE" 283 284 # Enable auto-scaling 285 is_auto_scaling_enabled = true 286 287 # Database backups 288 is_backup_retention_enabled = true 289 backup_retention_period_in_days = 7 290 } 291 ``` 292 293 ### Step 7: Object Storage 294 ```hcl 295 resource "oci_objectstorage_bucket" "backup" { 296 compartment_id = var.compartment_ocid 297 name = "app-backups" 298 namespace = data.oci_objectstorage_namespace.ns.namespace 299 access_type = "NoPublicAccess" 300 storage_tier = "Standard" 301 object_events_enabled = true 302 303 # Lifecycle rules 304 retention_rules { 305 display_name = "7-year-retention" 306 duration { 307 time_amount = 7 308 time_unit = "YEARS" 309 } 310 } 311 } 312 313 resource "oci_objectstorage_bucket" "cold_storage" { 314 compartment_id = var.compartment_ocid 315 name = "archived-logs" 316 namespace = data.oci_objectstorage_namespace.ns.namespace 317 access_type = "NoPublicAccess" 318 storage_tier = "Archive" 319 auto_tiering = "INFREQUENT_ACCESS" 320 } 321 ``` 322 323 ### Step 8: FastConnect (Dedicated Private Connectivity) 324 ```hcl 325 resource "oci_core_fast_connect_provider_service" "provider" { 326 provider_service_name = "Megaport" 327 } 328 329 resource "oci_core_virtual_circuit" "fc_primary" { 330 compartment_id = var.compartment_ocid 331 type = "PRIVATE" 332 display_name = "fastconnect-primary" 333 bandwidth = 1000 # 1 Gbps 334 customer_bgp_asn = 65550 335 provider_service_id = data.oci_core_fast_connect_provider_services.provider.fast_connect_provider_services[0].id 336 provider_service_key_name = "megaport-key-primary" 337 gateway_id = oci_core_drg.main.id 338 339 cross_connect_mappings { 340 customer_bgp_peering_ip = "10.200.0.1/30" 341 oracle_bgp_peering_ip = "10.200.0.2/30" 342 } 343 } 344 ``` 345 346 ### Step 9: Resource Manager (Terraform Automation) 347 ```hcl 348 resource "oci_resourcemanager_stack" "infra" { 349 compartment_id = var.compartment_ocid 350 display_name = "infrastructure-stack" 351 description = "Base infrastructure deployment" 352 config_source { 353 config_source_type = "GIT_CONFIG_SOURCE" 354 configuration_source_provider_id = oci_resourcemanager_configuration_source_provider.github.id 355 branch_name = "main" 356 } 357 } 358 359 resource "oci_resourcemanager_job" "apply" { 360 stack_id = oci_resourcemanager_stack.infra.id 361 job_operation_details { 362 operation = "APPLY" 363 apply_job_plan_resolution { 364 resolution_strategy = "ALWAYS_USE_LATEST_PLAN" 365 } 366 } 367 } 368 ``` 369 370 ### Step 10: Monitoring and Alerts 371 ```hcl 372 resource "oci_monitoring_alarm" "cpu_high" { 373 compartment_id = var.compartment_ocid 374 alarm_summary = "High CPU utilization" 375 display_name = "cpu-utilization-high" 376 metric_compartment_id = var.compartment_ocid 377 namespace = "oci_computeagent" 378 query = "CpuUtilization[1m].mean() > 90" 379 severity = "WARNING" 380 body = "CPU > 90% for >1 minute on {resource.display_name}" 381 destinations = [oci_ons_topic.alarms.id] 382 is_enabled = true 383 repeat_duration = "PT15M" 384 } 385 ``` 386 387 ## Rules 388 - Every resource must belong to a compartment — no root compartment resources. 389 - Use NSGs for instance-level security; use Security Lists for subnet defaults. 390 - Preflex Flex shapes over fixed OCPU shapes for cost efficiency and flexibility. 391 - Enable auto-scaling on Autonomous Database for unpredictable workloads. 392 - Use instance principals for OKE node pools to access object storage without keys. 393 - Tag all resources with a cost-tracking tag namespace (Environment, Project, Owner). 394 - Set up budgets and alerts before deploying production workloads. 395 - Use OCI Vault for secrets, API keys, and database passwords. 396 - Prefer FastConnect over site-to-site VPN for production hybrid connectivity. 397 - Enable OKE cluster audit logs and ship to OCI Logging. 398 399 ## Production Considerations 400 - OCI regions are organized by realm (commercial, government, China). Choose the right realm. 401 - Availability domains (AD) are isolated within a region — 3 ADs in commercial regions. 402 - Fault domains are within an AD — spread instances across all fault domains. 403 - Block volume performance scales with size — allocate >= 320 GB for max IOPS. 404 - OKE control plane is Oracle-managed (free) but node pools are your responsibility. 405 - Use reserved (prepaid) compute for steady-state workloads to save up to 60%. 406 - OCI Budgets support consumption-based and forecast-based alerts. 407 - Exadata Cloud Service is available for extremely large Oracle Database workloads. 408 - OCI WAF (Web Application Firewall) supports rate limiting, bot management, and CAPTCHA. 409 - OCI Bastion service provides SSH/RDP access to private instances without public IPs. 410 411 ## Anti-Patterns 412 - Using root compartment for resources — impossible to apply fine-grained policies. 413 - Using fixed OCPU shapes (VM.Standard2.x) instead of Flex — wasteful and inflexible. 414 - No VCN flow logs — can't troubleshoot connectivity issues. 415 - Direct internet access from private subnets without NAT gateway. 416 - S3 API compatibility assumed for OCI Object Storage — use OCI SDK or CLI. 417 - Using Security Lists exclusively without NSGs — broader blast radius. 418 - No budget alerts — surprise bills from misconfigured or attacked resources. 419 - Manually managing OKE node pools — let cluster autoscaler or node pool management handle it. 420 - Over-provisioning block volumes for IOPS — use performance tiers instead. 421 - Ignoring OCI announcements service — unplanned maintenance surprises. 422 423 ## References 424 - references/oci-compute.md — OCI Compute and Shapes 425 - references/oci-networking.md — VCN, Subnets, Security Lists, DRG 426 - references/oci-storage.md — Object Storage, Block Volume, File Storage 427 - references/oci-oke.md — OKE Cluster and Node Pool Management 428 - references/oracle-cloud-advanced.md — Oracle Cloud Advanced Topics 429 - references/oracle-cloud-fundamentals.md — Oracle Cloud Fundamentals 430 ## Handoff 431 - `devops-terraform` for Terraform state and module patterns for OCI. 432 - `devops-kubernetes` for workload deployment on OKE clusters. 433 - `devops-docker` for containerizing applications for OKE. 434 - `devops-hybrid-cloud` for connecting OCI with on-prem or other clouds. 435 - `devops-backup-dr` for OCI-based backup and DR strategies. 436 - `devops-observability` for OCI logging and monitoring integration. 437 438 ## Architecture Decision Trees 439 440 ### OCI IAM vs Federation 441 442 | Decision | OCI Native IAM | Federated (SSO/OIDC) | 443 |---|---|---| 444 | User management | OCI console, manual | Central IdP (Okta, Azure AD) | 445 | MFA | OCI built-in MFA | IdP-managed MFA | 446 | Group sync | Manual or API | SCIM provisioning | 447 | Audit trail | OCI Audit logs | IdP audit + OCI Audit | 448 | Complexity | Lower (in-platform) | Higher (IdP setup + mapping) | 449 | Best for | Small teams, isolated OCI | Enterprise with SSO requirement | 450 451 ### Compute Shapes: AMD vs ARM (Ampere) 452 453 | Aspect | AMD (Standard) | ARM / Ampere A1 | 454 |---|---|---| 455 | vCPU ratio | 1:2 per core | 1:1 per core | 456 | Price-performance | Baseline | 20-40% better for scale-out | 457 | Software compat | Universal | Requires ARM64 builds | 458 | GPU support | Available | Not available | 459 | Best for | General workloads, legacy | Containerized, web, K8s nodes | 460 461 ## Implementation Patterns 462 463 ### Terraform: OCI VCN with Public and Private Subnets 464 465 ```hcl 466 resource "oci_identity_compartment" "prod" { 467 name = "production" 468 description = "Production compartment" 469 } 470 471 resource "oci_core_vcn" "main" { 472 compartment_id = oci_identity_compartment.prod.id 473 display_name = "production-vcn" 474 cidr_block = "10.0.0.0/16" 475 dns_label = "prod" 476 477 defined_tags = { 478 "Operations.CostCenter" = "12345" 479 } 480 } 481 482 resource "oci_core_subnet" "public" { 483 compartment_id = oci_identity_compartment.prod.id 484 vcn_id = oci_core_vcn.main.id 485 cidr_block = "10.0.1.0/24" 486 display_name = "public-lb" 487 security_list_ids = [oci_core_security_list.lb.id] 488 route_table_id = oci_core_route_table.public.id 489 dhcp_options_id = oci_core_dhcp_options.main.id 490 dns_label = "public" 491 prohibit_public_ip_on_vnic = false 492 } 493 494 resource "oci_core_subnet" "private" { 495 compartment_id = oci_identity_compartment.prod.id 496 vcn_id = oci_core_vcn.main.id 497 cidr_block = "10.0.2.0/24" 498 display_name = "private-app" 499 security_list_ids = [oci_core_security_list.app.id] 500 route_table_id = oci_core_route_table.private.id 501 dhcp_options_id = oci_core_dhcp_options.main.id 502 dns_label = "private" 503 prohibit_public_ip_on_vnic = true 504 } 505 506 resource "oci_core_instance" "app" { 507 compartment_id = oci_identity_compartment.prod.id 508 display_name = "app-server-01" 509 shape = "VM.Standard.A1.Flex" 510 shape_config { 511 ocpus = 4 512 memory_in_gbs = 24 513 } 514 source_details { 515 source_type = "image" 516 source_id = var.ol8_image_id 517 } 518 create_vnic_details { 519 subnet_id = oci_core_subnet.private.id 520 assign_public_ip = false 521 } 522 metadata = { 523 ssh_authorized_keys = var.ssh_public_key 524 } 525 } 526 ``` 527 528 ### Bash: OCI CLI Automation for OKE 529 530 ```bash 531 #!/usr/bin/env bash 532 oci_login() { 533 oci session authenticate --region us-ashburn-1 534 } 535 536 oke_kubeconfig() { 537 local cluster_id=$1 538 oci ce cluster create-kubeconfig \ 539 --cluster-id "$cluster_id" \ 540 --file "${HOME}/.kube/oke-config" \ 541 --region us-ashburn-1 \ 542 --token-version 2.0.0 543 export KUBECONFIG="${HOME}/.kube/oke-config" 544 } 545 546 list_compartments() { 547 oci iam compartment list \ 548 --compartment-id-in-subtree true \ 549 --all \ 550 --query 'data[*].{Name:name, Id:id, State:"lifecycle-state"}' \ 551 --output table 552 } 553 ``` 554 555 ## Production Considerations 556 557 - Use **compartments** for resource isolation per team/environment with IAM policies at compartment level 558 - Enable **OCI Cloud Guard** target on every compartment for threat detection and misconfiguration alerts 559 - Configure **Vault (KMS)** for encryption keys — encrypt all block volumes, object storage, and databases 560 - Deploy **OKE clusters** with `--pod-cidr` and `--service-cidr` that don't overlap with on-prem or VCN ranges 561 - Use **Flex shapes** (VM.Standard.E5.Flex) for most workloads — better price-performance than fixed shapes 562 - Set up **budgets** at compartment level with threshold alerts to Slack/email 563 - Enable **VCN Flow Logs** for network traffic analysis and security investigation 564 565 ## Anti-Patterns 566 567 - Using **root compartment** for all resources — prevents fine-grained IAM and cost tracking 568 - Exposing **database ports (1521, 3306)** to 0.0.0.0/0 in security lists — always scope to app subnet 569 - Skipping **OCI Vulnerability Scanning Service** — containers and OS images should be scanned weekly 570 - Using **burstable shapes** (VM.Standard.E2.1.Micro) for production — they throttle CPU under load 571 - Ignoring **block volume backups** — enable automatic backups with 7-day retention as minimum 572 - Applying **broad IAM policies** at tenancy level — use compartment-level policies with conditions 573 - Over-provisioning **boot volumes** (default 50 GB) — resize only when needed to avoid waste 574 575 ## Performance Optimization 576 577 - Use **DenseIO shapes** for database and analytics workloads requiring high local NVMe performance 578 - Enable **FastConnect** for dedicated, low-latency connectivity to OCI regions 579 - Configure **load balancer** with session persistence and health checks for zero-downtime deployments 580 - Use **OCI Object Storage** with standard tier for frequently accessed data, infrequent tier for logs 581 - Tune **OKE worker node shapes** by workload: `VM.Standard.E5.Flex` for general, `BM.Optimized3.36` for AI/ML 582 - Enable **autoscaling** on OKE node pools with cluster autoscaler and spot instances for batch workloads 583 - Use **OCI Cache (Redis)** for session state and query result caching instead of local instance storage 584 585 ## Security Considerations 586 587 - Enable **OCI Identity Domain** with MFA for all console users — enforce password policies 588 - Use **resource principal** (instance principals) for OKE and Compute VMs — never store API keys 589 - Restrict **object storage bucket access** with pre-authenticated requests (PAR) and least-privilege policies 590 - Rotate **OCI API keys** every 90 days and use API key versioning for key rotation without downtime 591 - Enable **Cloud Guard** with detector recipes for storage, networking, and IAM misconfigurations 592 - Use **Vault (HSM)** for master encryption keys and auto-rotate DEKs every 180 days 593 - Audit **IAM policy changes** with OCI Audit logs and stream to OCI Object Storage for retention 594 ## Implementation Patterns 595 596 ### Observer Pattern for Event Handling 597 ` 598 interface EventObserver<T> { 599 onEvent(event: T): Promise<void>; 600 } 601 602 class EventBus<T> { 603 private observers: Set<EventObserver<T>> = new Set(); 604 subscribe(observer: EventObserver<T>): void { 605 this.observers.add(observer); 606 } 607 unsubscribe(observer: EventObserver<T>): void { 608 this.observers.delete(observer); 609 } 610 async emit(event: T): Promise<void> { 611 const results = Array.from(this.observers).map(o => o.onEvent(event)); 612 await Promise.allSettled(results); 613 } 614 } 615 ` 616 617 ### Configuration-Driven Approach 618 ` 619 config: 620 defaults: 621 timeout: 30s 622 retryCount: 3 623 overrides: 624 production: 625 timeout: 60s 626 retryCount: 5 627 development: 628 timeout: 300s 629 retryCount: 1 630 ` 631 632 ## Production Considerations 633 634 ### Deployment Checklist 635 - [ ] Configuration validated against schema before startup 636 - [ ] Health check endpoints registered and monitored 637 - [ ] Graceful shutdown with draining period (30s timeout) 638 - [ ] Resource limits configured (CPU, memory, file descriptors) 639 - [ ] Log level set appropriate for environment 640 - [ ] Metrics endpoint secured and exposed 641 - [ ] Rate limiting configured per-tier 642 - [ ] TLS certificates valid and auto-renewing 643 - [ ] Database migrations run as separate deployment step 644 - [ ] Feature flags ready for gradual rollout 645 646 ### Monitoring and Alerting 647 | Metric | Threshold | Severity | Action | 648 |--------|-----------|----------|--------| 649 | Error rate | > 1% over 5min | Critical | Page on-call | 650 | p99 latency | > 2s over 5min | Warning | Investigate | 651 | Throughput drop | > 50% over 1min | Critical | Check upstream | 652 | Queue depth | > 1000 over 1min | Warning | Scale consumers | 653 | Disk usage | > 85% | Warning | Clean or expand | 654 | Memory usage | > 90% heap | Critical | Restart or scale | 655 656 ## Anti-Patterns 657 658 | Anti-Pattern | Symptom | Root Cause | Solution | 659 |-------------|---------|------------|----------| 660 | Premature optimization | Complex code for no measured benefit | Guessing instead of profiling | Measure first, optimize based on data | 661 | Copy-paste reuse | Duplicate code across codebase | Lack of abstraction | Extract shared logic into libraries | 662 | Gold-plating | Features with no current requirement | Over-engineering | YAGNI — build what's needed now | 663 | Magical thinking | Assumptions without validation | Skipping error handling | Handle all failure modes explicitly | 664 665 ## Performance Optimization 666 667 ### Caching Strategy 668 Cache hierarchy: L1 (in-memory local) → L2 (distributed Redis/Memcached) → L3 (CDN/Edge). 669 Cache invalidation: TTL-based (simple, stale), event-based (complex, fresh), write-through (consistent, higher write latency), write-behind (fast writes, eventual consistency). 670 671 ### Resource Pooling 672 - Database connections: Pool of reusable connections (HikariCP, pgBouncer) 673 - HTTP connections: Keep-alive + connection pooling for external calls 674 - Thread pool: Bounded thread pools for async task execution 675 676 ### Profiling Methodology 677 1. Establish baseline with production traffic profile 678 2. Profile CPU with sampling profiler (pprof, perf, async-profiler) 679 3. Profile memory with heap dumps and allocation tracking 680 4. Profile I/O with strace/perf trace for syscall analysis 681 5. Profile latency with distributed tracing (OpenTelemetry) 682 6. Identify bottleneck, formulate hypothesis, implement fix 683 7. Re-profile to verify improvement, repeat 684 685 ## Security Considerations 686 687 ### Threat Modeling (STRIDE) 688 - Spoofing: Identity validation, authentication 689 - Tampering: Integrity checks, digital signatures 690 - Repudiation: Audit logs, non-repudiation 691 - Information disclosure: Encryption, access control 692 - Denial of service: Rate limiting, resource quotas 693 - Elevation of privilege: Principle of least privilege 694 695 ### Supply Chain Security 696 - Dependency scanning: Snyk, Dependabot, Trivy 697 - SBOM generation: CycloneDX or SPDX format 698 - Signed commits: GPG or SSH commit signing 699 - Artifact verification: Checksum validation, signature verification 700 701 ### Secrets Management 702 - Secrets never in code — always in secrets manager (Vault, AWS Secrets Manager) 703 - Rotation policy: Rotate database credentials every 90 days 704 - Access audit: Log every secrets access, alert on anomalies 705 - Encryption at rest and in transit for all secrets 706 - Principle of least privilege: each service gets only its own secrets 707 708 ## Rules 709 - Default-deny security posture — allow only explicitly required access. 710 - All inputs validated, all outputs encoded, all errors handled. 711 - Defend in depth — multiple layers of security controls. 712 - Fail securely — errors default to safe behavior. 713 - Log security-relevant events for audit and investigation. 714 - Keep dependencies updated — automate vulnerability scanning. 715 - Design for observability from day one, not as an afterthought. 716 - Document all architectural decisions with rationale. 717 - Review code for security, performance, and correctness before merging.