Processes
A process is an instance of a running program. Every backend application runs as one or more processes.
Process vs Program
- Program: Static code on disk (your JAR file)
- Process: Running instance of that program (java -jar app.jar)
Process States
Created --> Ready --> Running --> Terminated
^ |
| v
+---- Waiting (I/O)
| State | Description |
|---|---|
| Created | Process is being created |
| Ready | Waiting to be assigned to CPU |
| Running | Instructions being executed |
| Waiting | Waiting for I/O operation |
| Terminated | Finished execution |
Process Management
# View processes
ps aux | grep java
# Kill a process
kill -9 <PID>
# View process resources
top
htop
# Background process
java -jar app.jar &
Process in Backend
When you start a Spring Boot application:
java -jar myapp.jar
This creates a JVM process that:
- Loads your application code
- Starts the embedded Tomcat server
- Listens on a port for requests
- Handles requests using threads
Multiple Processes
Production backends often run multiple processes:
Process 1: Java Application (port 8080)
Process 2: Nginx (port 80)
Process 3: Redis (port 6379)
Process 4: PostgreSQL (port 5432)
Process vs Thread
| Feature | Process | Thread |
|---|---|---|
| Memory | Separate | Shared |
| Creation | Heavy | Light |
| Communication | IPC (complex) | Shared memory (simple) |
| Isolation | Strong | Weak |
Best Practices
Key Principles
- Follow SOLID principles
- Write clean, readable code
- Test thoroughly
- Document decisions
- Monitor in production
Implementation
- Start simple, refactor as needed
- Use established patterns
- Consider trade-offs
- Review with peers
Continuous Improvement
- Learn from incidents
- Update documentation
- Share knowledge
- Mentor others
Key Points
- Understanding Processes is essential for production systems
- Always consider scalability and maintainability
- Test thoroughly before deploying to production
- Monitor performance and set up alerting
Common Patterns
- Validation: Always validate input at the boundary
- Error Handling: Use structured error responses
- Logging: Log key events for debugging
- Testing: Unit, integration, and load tests
- Documentation: Keep docs updated with code changes
Practice Problems
Design and implement a solution for Processes in a backend system. Consider scalability, error handling, and production readiness.
Solution
// Processes implementation
// Key aspects: validation, error handling, logging, testing
public class Processes {
// Production-ready implementation
}Identify and handle edge cases for Processes. What happens under high load, with invalid input, or during failures?
Solution
// Edge case handling:
// 1. Null/empty input -> validation
// 2. High load -> rate limiting, queuing
// 3. Failures -> retries, circuit breaker
// 4. Concurrent access -> locks, idempotencyWrite a testing strategy for Processes. Include unit tests, integration tests, and performance tests.
Solution
// Test plan:
// - Unit: 80% coverage target
// - Integration: API contracts
// - Performance: latency, throughput
// - Chaos: failure injectionQuiz
1. What is the difference between a program and a process?
2. Which state is a process in when waiting for I/O?
3. What is the primary purpose of Processes?
4. What is a common mistake when implementing Processes?
Flashcards
Question
What is a process?
Click to reveal answer
Answer
A running instance of a program
Question
Process vs Thread?
Click to reveal answer
Answer
Process: separate memory. Thread: shared memory
Question
What is Processes?
Click to reveal answer
Answer
Processes is a key concept in backend development.
Question
When to use Processes?
Click to reveal answer
Answer
Use Processes when building production systems that require reliability, scalability, and maintainability.
Question
Processes best practices
Click to reveal answer
Answer
Follow SOLID principles, write clean code, test thoroughly, document decisions, and monitor in production.
Revision Notes
Key Takeaways
- 1.Process = running program instance
- 2.States: Created, Ready, Running, Waiting, Terminated
- 3.Each backend service runs as a process
- 4.Processes have separate memory; threads share memory
Interview Tips
- •Know the difference between process and thread
- •Understand process lifecycle
Cheat Sheet
Processes
- Process: Running program instance
- States: Created -> Ready -> Running -> Terminated
- vs Thread: Process=separate memory, Thread=shared memory